forked from lda/telodendria
Add a static JsonEncodeString() method.
Right now it just calls fprintf(), but in the future, it will properly encode a string for JSON output.
This commit is contained in:
parent
02f8c4bb82
commit
644733c74e
1 changed files with 9 additions and 2 deletions
11
src/Json.c
11
src/Json.c
|
@ -248,6 +248,12 @@ JsonValueFree(JsonValue * value)
|
|||
free(value);
|
||||
}
|
||||
|
||||
static void
|
||||
JsonEncodeString(const char * str, FILE * out)
|
||||
{
|
||||
fprintf(out, "\"%s\"", str);
|
||||
}
|
||||
|
||||
static void
|
||||
JsonEncodeValue(JsonValue * value, FILE * out)
|
||||
{
|
||||
|
@ -278,7 +284,7 @@ JsonEncodeValue(JsonValue * value, FILE * out)
|
|||
fputc(']', out);
|
||||
break;
|
||||
case JSON_STRING:
|
||||
fprintf(out, "\"%s\"", value->as.string);
|
||||
JsonEncodeString(value->as.string, out);
|
||||
break;
|
||||
case JSON_INTEGER:
|
||||
fprintf(out, "%lld", value->as.integer);
|
||||
|
@ -328,7 +334,8 @@ JsonEncode(HashMap * object, FILE * out)
|
|||
index = 0;
|
||||
while (HashMapIterate(object, &key, (void **) &value))
|
||||
{
|
||||
fprintf(out, "\"%s\":", key);
|
||||
JsonEncodeString(key, out);
|
||||
fputc(':', out);
|
||||
JsonEncodeValue(value, out);
|
||||
|
||||
if (index < count - 1)
|
||||
|
|
Loading…
Reference in a new issue