大佬教程收集整理的这篇文章主要介绍了使用cjson库解析json格式,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
配置文件cfg.ini
{ "status": "ok","code": 0,"devices": [ { "device_id": "dd87336a-56ba-dd88-c698-74ffba1a8886","device_name": "nliu","device_mac": "00AABBCCDD","geoip": "上海市 电信" } ] }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "json.h" int main(int argc,char **argv) { struct json_object *new_obj; struct json_object *obj; new_obj = json_object_from_file("a"); json_object_object_foreach(new_obj,key,val) { if (strcmp(key,"devices") == 0) { // printf("%s\n",json_object_to_json_string(val)); struct array_list* arr = json_object_get_array(val); printf("1 DEBUG %d\n",json_object_array_length(val)); struct json_object* obj = (struct json_object*)array_list_get_idx(arr,0); printf("%s\n",json_object_get_string(obj)); json_object_object_foreach(obj,key1,val1) { printf("key %s,:::%s\n",json_object_to_json_string(val1)); } } else { // printf("\t%s: %s\n",json_object_to_json_string(val)); } } json_object_put(new_obj); return 0; }
以上是大佬教程为你收集整理的使用cjson库解析json格式全部内容,希望文章能够帮你解决使用cjson库解析json格式所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。