这是要处理的json对象,{\"All\":2,\"Dots\":[{\"C\":1,\"D\":1,\"I\":1,\"T\":0},{\"C\":1,\"D\":1,\"I\":1,\"T\":1}]}我期望得到的结果是:[{"C":1,"D":1,"I":1,"T":0,"V":0.0},{"C...
这是要处理的json对象,{\"All\":2, \"Dots\":[{\"C\":1,\"D\":1,\"I\":1,\"T\":0},{\"C\":1,\"D\":1,\"I\":1,\"T\":1}]}
我期望得到的结果是:[{"C":1,"D":1,"I":1,"T":0,"V":0.0},{"C":1,"D":1,"I":1,"T":1,"V":2727.0}]
我已经完成了部分工作,代码如下:
new_obj= json_tokener_parse("{\"All\":2,\"Dots\":[{\"C\":1,\"D\":1,\"I\":1,\"T\":0},{\"C\":1,\"D\":1,\"I\":1,\"T\":1}]}");
fprintf(cgiOut,"<h3>my_object.to_string()=%s\n</h3>", json_object_to_json_string(new_obj)); json_object_object_add(new_obj,"V",json_object_new_string("2727.0"));
struct json_object *o = json_object_object_get(new_obj,"Dots"); fprintf(cgiOut,"<h3>my_object.to_string()=%s\n</h3>", json_object_to_json_string(new_obj));fprintf(cgiOut,"<h3>Dots.to_string()=%s\n</h3>", json_object_to_json_string(o));
这段代码,产生的效果如下:
小弟是菜鸟,请各位大神指教!