zxc_alone 2016-11-07 02:06 采纳率: 0%
浏览 1529

json 解析,怎么根据_className里面的值获取properties里面的id

{
"version": "2.0",
"refs": {
"3": {
"_classPath": "Q.Graphs.server"
}
},
"datas": [
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.21",
"properties": {
"data": {
"name": "192.168.5.21",
"x": 303,
"y": -39,
"id": 1
}
},
"location": {
"x": 303,
"y": -39
},
"image": {
"$ref": 3
}
},
"_refId": "346"
},
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.26",
"properties": {
"data": {
"name": "192.168.5.26",
"x": 399,
"y": 226,
"id": 2
}
},
"location": {
"x": 399,
"y": 226
},
"image": {
"$ref": 3
}
},
"_refId": "348"
},
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.80",
"properties": {
"data": {
"name": "192.168.5.80",
"x": 69,
"y": 35,
"id": 3
}
},
"location": {
"x": 69,
"y": 35
},
"image": {
"$ref": 3
}
},
"_refId": "350"
},
{
"_className": "Q.Node",
"json": {
"name": "0.0.0.0",
"properties": {
"data": {
"name": "0.0.0.0",
"x": -158,
"y": -57.80000000000001,
"id": 529
}
},
"location": {
"x": -158,
"y": -57.80000000000001
},
"image": {
"$ref": 3
}
},
"_refId": "352"
},
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.80",
"properties": {
"data": {
"name": "192.168.5.80",
"x": 2,
"y": 2,
"id": 602
}
},
"location": {
"x": 2,
"y": 2
},
"image": {
"$ref": 3
}
}
},
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.26",
"properties": {
"data": {
"name": "192.168.5.26",
"x": 3,
"y": 2,
"id": 601
}
},
"location": {
"x": -54,
"y": 70
},
"image": {
"$ref": 3
}
}
},
{
"_className": "Q.Node",
"json": {
"name": "192.168.5.24",
"properties": {
"data": {
"name": "192.168.5.24",
"x": 77,
"y": -49,
"id": 5
}
},
"location": {
"x": 77,
"y": -49
},
"image": {
"$ref": 3
}
},
"_refId": "358"
},
{
"_className": "Q.Node",
"json": {
"name": "123.123",
"properties": {
"data": {
"name": "123.123",
"x": 436,
"y": -38,
"id": 521
}
},
"location": {
"x": 436,
"y": -38
},
"image": {
"$ref": 3
}
},
"_refId": "360"
},
{
"_className": "Q.Edge",
"json": {
"properties": {
"data": {
"connectType": "lineZ",
"name": "",
"from": 521,
"to": 1
}
},
"from": {
"_ref": 360
},
"to": {
"_ref": 346
},
"edgeType": "lineZ"
}
},
{
"_className": "Q.Edge",
"json": {
"properties": {
"data": {
"connectType": "lineZ",
"name": "",
"from": 1,
"to": 3
}
},
"from": {
"_ref": 346
},
"to": {
"_ref": 350
},
"edgeType": "lineZ"
}
},
{
"_className": "Q.Edge",
"json": {
"properties": {
"data": {
"connectType": "lineZ",
"name": "",
"from": 5,
"to": 1
}
},
"from": {
"_ref": 358
},
"to": {
"_ref": 346
},
"edgeType": "lineZ"
}
},
{
"_className": "Q.Edge",
"json": {
"properties": {
"data": {
"connectType": "orthogonal.V.H",
"name": "",
"from": 521,
"to": 2
}
},
"from": {
"_ref": 360
},
"to": {
"_ref": 348
},
"edgeType": "orthogonal.V.H"
}
},
{
"_className": "Q.Edge",
"json": {
"properties": {
"data": {
"connectType": "lineZ",
"name": "",
"from": 529,
"to": 3
}
},
"from": {
"_ref": 352
},
"to": {
"_ref": 350
},
"edgeType": "lineZ"
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 580
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 581
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 605
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 603
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 604
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
},
{
"_className": "Q.Group",
"json": {
"name": "Group",
"properties": {
"data": {
"name": "Group",
"x": -185.2,
"y": 81.2,
"id": 579
}
},
"location": {
"x": -185.2,
"y": 81.2
}
}
}
],
"scale": 1,
"tx": 274.84999999999997,
"ty": 136.70000000000002
}

  • 写回答

6条回答 默认 最新

  • Compostela 2016-11-07 02:12
    关注

    / 将json字符串转换为json对象
    jsonObj = new JSONObject(jsonStr);
    // 得到指定json key对象的value对象
    JSONArray personList = jsonObj.getJSONArray("persons");
    // 遍历jsonArray
    for (int i = 0; i < personList.length(); i++)
    {
    // 获取每一个json对象
    JSONObject jsonItem = personList.getJSONObject(i);
    // 获取每一个json对象的值
    Person person = new Person();
    person.setId(jsonItem.getInt("id"));
    person.setName(jsonItem.getString("name"));
    person.setAddress(jsonItem.getString("address"));
    list.add(person);
    }
    可以照着这样试试

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100