如何在c编程中将[和]附加到json对象....
我喜欢
json_builder_begin_object(builder);
json_builder_set_member_name( builder, "response" );
json_builder_add_string_value( builder, "success" );
json_builder_set_member_name( builder, "data" );
json_builder_begin_object( builder );
json_builder_set_member_name( builder, "type" );
json_builder_add_string_value( builder, "vehicle " );
json_builder_set_member_name( builder, "value" );
json_builder_add_string_value( builder, ">10lakhs " );
json_builder_set_member_name(builder,"color");
json_builder_add_string_value(builder,"Black");
我需要像
这样的回复[{ “响应”: “成功”}, “数据”[{ “类型”: “车辆”},{ “值”: “> 10lakhs”},{ “颜色”: “黑”}] ]
-Thanks提前.. :) :)
答案 0 :(得分:0)
您必须使用set_member_name和begin_object。前者设置子对象的名称,后者设置子对象的名称,以便其余数据进入其中。
例如,来自我的Countly app:
json_builder_begin_object (builder);
if(crash->hardware){
json_builder_set_member_name (builder, "hardware");
json_builder_begin_object(builder);
if(crash->hardware->os){
json_builder_set_member_name (builder, "_os");
json_builder_add_string_value (builder, crash->hardware->os);
}
if(crash->hardware->os_version) {
json_builder_set_member_name (builder, "_os_version");
json_builder_add_string_value (builder, crash->hardware->os_version);
}
if(crash->hardware->manufacture) {
json_builder_set_member_name (builder, "_manufacture");
json_builder_add_string_value (builder, crash->hardware->manufacture);
}
if(crash->hardware->device) {
json_builder_set_member_name (builder, "_device");
json_builder_add_string_value (builder, crash->hardware->device);
}
if(crash->hardware->resolution) {
json_builder_set_member_name (builder, "_resolution");
json_builder_add_string_value (builder, crash->hardware->resolution);
}
if(crash->hardware->app_version) {
json_builder_set_member_name (builder, "_app_version");
json_builder_add_string_value (builder, crash->hardware->app_version);
}
if(crash->hardware->cpu) {
json_builder_set_member_name (builder, "_cpu");
json_builder_add_string_value (builder, crash->hardware->cpu);
}
if(crash->hardware->opengl) {
json_builder_set_member_name (builder, "_opengl");
json_builder_add_string_value (builder, crash->hardware->opengl);
}
json_builder_end_object (builder);
}