json json数据解析
2022-12-22 14:05:08 最后更新
用法:
//解析json数据,双引号要加 \ 进行转义
Object text = "{\"id\":1, \"name\":\"xiaobai\", \"age\":16}";
Object jo = i.json(text);

//获取id
Object a = i.json(jo, "get", "id");
syso(a);
//获取name
Object b = i.json(jo, "get", "name");
syso(b);
//获取age
Object c = i.json(jo, "get", "age");
syso(c);

//修改age数据
i.json(jo, "set", "age", 20);

//删除id数据
i.json(jo, "del", "id");

//打印json数据
Object text = i.json(jo, "json");
syso(text);

//解析json列表数据
Object text = "{\"userlist\":[{\"id\":1, \"name\":\"niubi\", \"age\":16},{\"id\":2, \"name\":\"wangba\", \"age\":18},{\"id\":3, \"name\":\"goudan\", \"age\":17}]}";
Object jo = i.json(text);

//打印json数据
Object list = i.json(jo, "list", "userlist");
Object size = i.json(list, "size");
while(size > 0){

size = size - 1;

Object item = i.json(list, "data", size);

//获取id
Object a = i.json(item, "get", "id");
syso(a);
//获取name
Object b = i.json(item, "get", "name");
syso(b);
//获取age
Object c = i.json(item, "get", "age");
syso(c);

}

说明:
常用于解析服务器反馈的数据。