Preserve the original string representation of numbers too.

Not always useful, but sometimes it will be.
This commit is contained in:
Eric Fischer 2014-02-26 17:00:10 -08:00
parent 0509a860fb
commit 73cf86acdb
2 changed files with 8 additions and 3 deletions

View File

@ -99,7 +99,9 @@ have no additional data.
Strings have type <code>JSON_STRING</code>, with null-terminated UTF-8 text
in <code>string</code> and length in <code>length</code>.
Numbers have type <code>JSON_NUMBER</code>, with value in <code>number</code>.
Numbers have type <code>JSON_NUMBER</code>, with value in <code>number</code>,
and also preserve the original representation of the number
in <code>string</code> and length in <code>length</code>.
Arrays have type <code>JSON_ARRAY</code>. There are <code>length</code> elements in the array,
and the elements are in <code>array</code>.

View File

@ -414,8 +414,11 @@ again:
json_object *n = add_object(j, JSON_NUMBER);
if (n != NULL) {
n->number = atof(val.buf);
n->string = val.buf;
n->length = val.n;
} else {
string_free(&val);
}
string_free(&val);
return n;
}
@ -542,7 +545,7 @@ void json_free(json_object *o) {
free(k);
free(v);
} else if (o->type == JSON_STRING) {
} else if (o->type == JSON_STRING || o->type == JSON_NUMBER) {
free(o->string);
}