Home > Back-end >  Complex parsing json
Complex parsing json

Time:02-09

 
{
"Properties" : [{
"XmlColumnNumber" : 0,
"ChildElements" : {
"Property" : [{
"XmlColumnNumber" : 0,
"ChildElements" : {},
"ExtensionElements" : {},
"Name" : "property,"
"Namespace" : "http://activiti.org/bpmn",
"Attributes" : {
"Name" : [{
"Name" : "name",
"Value" : "anniu"
},
"Value" : [{
"Name" : "value",
"Value" : "save"
}]
},
"NamespacePrefix" : "activiti,"
"XmlRowNumber" : 0
}, {
"XmlColumnNumber" : 0,
"ChildElements" : {},
"ExtensionElements" : {},
"Name" : "property,"
"Namespace" : "http://activiti.org/bpmn",
"Attributes" : {
"Name" : [{
"Name" : "name",
"Value" : "anniu"
},
"Value" : [{
"Name" : "value",
"Value" : "modify"
}]
},
"NamespacePrefix" : "activiti,"
"XmlRowNumber" : 0
}]
},
"ExtensionElements" : {},
"Name" : "properties",
"Namespace" : "http://activiti.org/bpmn",
"Attributes" : {},
"NamespacePrefix" : "activiti,"
"XmlRowNumber" : 0
}]
}

Such a json
 
{
"XmlColumnNumber" : 0,
"ChildElements" : {},
"ExtensionElements" : {},
"Name" : "property,"
"Namespace" : "http://activiti.org/bpmn",
"Attributes" : {
"Name" : [{
"Name" : "name",
"Value", "url"
},
"Value" : [{
"Name" : "value",
"Value" : "www.baidu.com"
}]
},
"NamespacePrefix" : "activiti,"
"XmlRowNumber" : 0
}
this is a dynamic uncertain how much
I finally to obtain anniu: save, url:www.baidu.com
This format.

CodePudding user response:

This is a list -- --
This is not complex json.

CodePudding user response:

Parse the HTML code is as follows:
 
String STR="you above the Json data";
The StringBuilder sbResult=new StringBuilder ();
JSONObject JSONObject=JSON. ParseObject (STR);
JSONArray properties=jsonObject. GetJSONArray (" properties ");
For (the Object property: the properties) {
JSONObject pro=(JSONObject) property;
JSONObject childElements=pro. GetJSONObject (" childElements ");
JSONArray property1=childElements. GetJSONArray (" property ");
For (Object o: property1) {
JSONObject tempPro=(JSONObject) o;
JSONObject attributes=tempPro. GetJSONObject (" attributes ");
JSONArray name=attributes. GetJSONArray (" name ");
JSONObject jsonObject1=name. GetJSONObject (0);
The String value=https://bbs.csdn.net/topics/jsonObject1.getString (" value ");
SbResult. Append (value + ":");
JSONArray value1=attributes. GetJSONArray (" value ");
JSONObject jsonObject2=value1. GetJSONObject (0);
String=value2 jsonObject2. Get String (" value ");
SbResult. Append (value2 + ", ");
}
}

CodePudding user response:

Is this a map? Using Json utility class parsed into the map, the get (" "key" ") can get the corresponding value
  • Related