1 Star 0 Fork 16

Ant_onio/propwd

forked from rENYI/propwd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xl.c 2.70 KB
一键复制 编辑 原始数据 按行查看 历史
renyi 提交于 2016-06-04 14:35 . done
#include <json.h>
#include <stdio.h>
void json_parse(json_object * jobj) {
enum json_type type;
json_object_object_foreach(jobj, key, val) {
//type = json_object_get_type(val);
//switch (type) {
// case json_type_string: printf("type: json_type_string, ");
printf("%s =>%s\n", key, json_object_get_string(val));
if (key == 'result'){
json_object * jobj = json_tokener_parse(json_object_get_string(val));
json_parse(jobj);
}
// break;
//}
}
}
int main()
{
char * string = "{\"jsonrpc\":\"2.0\",\"id\":0,\"result\":[0,{\"device_id\":\"INyRyS5Y6166\",\"device_name\":\"Ren\",\"device_sn\":\"ACPZ0FC206166\",\"system_name\":\"挖矿固件\",\"system_version\":\"V1.2.135\",\"hardware_model\":\"WS1508\",\"mac_address\":\"B0:D5:9D:62:86:EF\",\"lan_ip\":\"192.168.1.143\",\"account_id\":\"469956463\",\"account_name\":\"469956463\",\"product_id\":321,\"disk_quota\":\"10995116277760\",\"schedule_hours\":\"[ { \\\"from\\\": 0, \\\"to\\\": 24, \\\"type\\\": \\\"unlimit\\\", \\\"params\\\": { } } ]\"}]}";
printf ("JSON string: %s\n", string);
json_object * jobj = json_tokener_parse(string);
json_parse(jobj);
struct json_object *result_object = NULL;
struct json_object *result_object1 = NULL;
struct json_object *result_object2 = NULL;
result_object = json_object_object_get(jobj, "result");
printf("-----------result_object method ---------------------------\n");
printf("%s\n", json_object_to_json_string(result_object));
printf("-----------result_object method---------------------------\n");
result_object = json_object_array_get_idx(result_object, 1);
result_object1 = json_object_object_get(result_object, "device_id");
printf("-----------device_id method ---------------------------\n");
printf("%s\n", json_object_to_json_string(result_object1));
printf("-----------device_id method---------------------------\n");
result_object2 = json_object_object_get(result_object, "device_name");
printf("-----------device_name method ---------------------------\n");
printf("%s\n", json_object_to_json_string(result_object2));
printf("-----------device_name method---------------------------\n");
/*
char passsend[1000];
sprintf(passsend, "{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"call\",\"params\":[\"\",\"netcfg\",\"set_device_discovery\",{\"device_id\":\"INyRyS5Y6166\",\"device_name\":\"jj\",\"device_password\":\"u6ZPLocu\"}]}");
printf("%s\n\n",passsend);
*/
char * device_id = "INyRyS5Y6166";
char * device_name = "kuangji";
char * device_password ="000000";
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ant_onio/propwd.git
[email protected]:ant_onio/propwd.git
ant_onio
propwd
propwd
master

搜索帮助