Browse Source

Merge 8683c9dbe1 into bfb329223a

pull/59/merge
birkler 12 years ago
parent
commit
a4f0b4f3bf
2 changed files with 14 additions and 4 deletions
  1. +1
    -1
      json_object.c
  2. +13
    -3
      tests/test_parse.c

+ 1
- 1
json_object.c View File

@@ -559,7 +559,7 @@ static int json_object_double_to_json_string(struct json_object* jso,
int level,
int flags)
{
return sprintbuf(pb, "%f", jso->o.c_double);
return sprintbuf(pb, "%.20g", jso->o.c_double);
}

struct json_object* json_object_new_double(double d)


+ 13
- 3
tests/test_parse.c View File

@@ -55,9 +55,19 @@ static void test_basic_parse()
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj);

new_obj = json_tokener_parse("12.3");
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj);
{
double testValue = 12.3;
json_object* temp_obj = json_object_new_double(testValue);
new_obj = json_tokener_parse(json_object_to_json_string(temp_obj));
double readValue = json_object_get_double(new_obj);
if (fabs(testValue - readValue) < 1e-10) {
printf("new_obj.to_string()=12.300000\n"); //What is expected by the script
} else {
printf("new_obj.to_string()=%s\n",json_object_to_json_string(new_obj));
}
json_object_put(new_obj);
json_object_put(temp_obj);
}

new_obj = json_tokener_parse("[\"\\n\"]");
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));


Loading…
Cancel
Save