new jansson user here. I am currently using json_pack, but I need to break it up in small pieces. This is what I have now (in reality many more fields):
新jansson用户在这里。我目前正在使用json_pack,但我需要将它分解成小块。这就是我现在拥有的(实际上还有更多领域):
elm = json_pack("{ s:s, s:s, s:s }", "field1", "value1","field2", "value2","field3", "value3");
result being:
{
"field1": "value1",
"field2": "value2",
"field3": "value3"
}
I need to break this up in three calls, tried this, but it does not work:
我需要在三次调用中解决这个问题,试过这个,但它不起作用:
elm = json_pack("{ s:s }", "field1", "value1");
elm = json_pack("{ o, s:s }", elm, "field2", "value2");
elm = json_pack("{ o, s:s }", elm, "field3", "value3");
Expected result in elm the same as the first call above, but I end up with an empty object. Is what I want possible? Does anyone have an example?
elm中的预期结果与上面的第一个调用相同,但我最终得到一个空对象。我想要的是什么?有人有例子吗?
1 个解决方案
#1
1
Apparently not, but I reverted to the old-school way:
显然不是,但我恢复了老派的方式:
elm = json_object();
json_object_set_new(elm, "fleld1", json_string("value1"));
json_object_set_new(elm, "fleld2", json_string("value2"));
json_object_set_new(elm, "fleld3", json_string("value3"));
This fixed my problem.
这解决了我的问题。
#1
1
Apparently not, but I reverted to the old-school way:
显然不是,但我恢复了老派的方式:
elm = json_object();
json_object_set_new(elm, "fleld1", json_string("value1"));
json_object_set_new(elm, "fleld2", json_string("value2"));
json_object_set_new(elm, "fleld3", json_string("value3"));
This fixed my problem.
这解决了我的问题。