使用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;
}

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...