{
"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
}
/ 将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);
}
可以照着这样试试
什么语言解析?循环解析键值对 。
我擦,真长
首先,json 数据的基本格式:{["",""]}每两个双引号都是一一对应的一组数据。
根据基本格式入手,
用org.json.*解析
String str = {.........你的那个json 串}
String str = "";//你上面的json 数据串
JSONObject obj = new JSONObject(str);
JSONObject datas = obj.getJSONObject("datas");//根据get方法参数为对象名即一组双引号中第一个双引号的内容
JSONObject json = datas.getJSONObject("json");
JSONObject properties = json.getJSONObject("properties");
JSONObject data = properties.getJSONObject("data");//一级一级获取对象,现在获取到data对象,然后根据标识符获取对应数据
int id = data.getInt("id");//1
String name = data.getString("name");//就这样获取,这个name 是data对象的不是properties对象的
JS 实现
for dataobj in obj.datas[0]
{
if (dataobj._className=''??")
{
return dataobj.json.properties.id
}
}
数据真他妈长啊,,鼠标我都滑坏了。。
我自己大概写了一下。楼主可以照着改动改动。我自己写的比较简单,只是为了求结果。
public static void main(String[] args) {
String str ="{\"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.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\"}";
JSONObject object = JSONObject.fromObject(str);
JSONArray dataArray = object.getJSONArray("datas");
for (int i = 0; i < dataArray.size(); i++) {
JSONObject temp = dataArray.getJSONObject(i);
JSONObject json = temp.getJSONObject("json");
System.out.println("properties==="+json.getString("properties"));
JSONObject properties = json.getJSONObject("properties");
JSONObject data = properties.getJSONObject("data");
System.out.println(data.getString("id"));
}
}