无法在android中解析复杂的JSON响应
我无法解析JSON数据,这在解析时有点混乱。我试过很多方法,但我做不到。我不熟悉JSON解析。谁能帮帮我吗无法在android中解析复杂的JSON响应,android,json,Android,Json,我无法解析JSON数据,这在解析时有点混乱。我试过很多方法,但我做不到。我不熟悉JSON解析。谁能帮帮我吗 { "pulse_updates_id": 203, "poster": { "id": 0, "name": "test" }, "postermodel": { "id": 0, "name": "modeltest" }, "STM1": [ { "provider": "MM", "option
{
"pulse_updates_id": 203,
"poster": {
"id": 0,
"name": "test"
},
"postermodel": {
"id": 0,
"name": "modeltest"
},
"STM1": [
{
"provider": "MM",
"options": [
{
"itValue": 11.3,
"imValue": 16.3,
"sqValue": 24.4,
"description": "test description",
"isAvailable": false
},
{
"itValue": 14.3,
"imValue": 11.3,
"sqValue": 54.4,
"description": "test description2",
"isAvailable": true
}
],
"status": false,
"name": "testname",
"id": "984793353",
"testValue": {
"id": 0,
"name": "TestName"
},
"testIssue": {
"id": 0,
"name": "Issue"
}
}
],
"DTVG": null,
"RIP": null,
"HTSD": null,
"STM5": null,
"IdentificationNumber": null,
"Value": null
}
我得到了JSON的回应
谢谢。private void parseJson(JSONObject数据){
private void parseJson(JSONObject data) {
if (data != null) {
Iterator<String> it = data.keys();
while (it.hasNext()) {
String key = it.next();
try {
if (data.get(key) instanceof JSONArray) {
JSONArray arry = data.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
parseJson(arry.getJSONObject(i));
}
} else if (data.get(key) instanceof JSONObject) {
parseJson(data.getJSONObject(key));
} else {
System.out.println("Key :" + key);
System.out.println("Value :" + data.getString(key));
}
} catch (Throwable e) {
try {
System.out.println("Key :" + key);
System.out.println("Value :" + data.getString(key));
} catch (Exception ee) {
}
e.printStackTrace();
}
}
}
}
如果(数据!=null){
迭代器it=data.keys();
while(it.hasNext()){
String key=it.next();
试一试{
if(data.get(key)instanceof JSONArray){
JSONArray arry=data.getJSONArray(key);
int size=arry.length();
对于(int i=0;i
试试这个递归函数
调用此函数并查看日志
This will parse any json object.
private void parseJson(JSONObject data) {
if (data != null) {
Iterator<String> it = data.keys();
while (it.hasNext()) {
String key = it.next();
try {
if (data.get(key) instanceof JSONArray) {
JSONArray arry = data.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
parseJson(arry.getJSONObject(i));
}
} else if (data.get(key) instanceof JSONObject) {
parseJson(data.getJSONObject(key));
} else {
System.out.println("Key : " + key);
System.out.println("Value : " + data.getString(key));
}
} catch (Throwable e) {
try {
System.out.println("Key : " + key);
System.out.println("Value : " + data.getString(key));
} catch (Exception ee) {
}
e.printStackTrace();
}
}
}
}
这将解析任何json对象。
私有void parseJson(JSONObject数据){
如果(数据!=null){
迭代器it=data.keys();
while(it.hasNext()){
String key=it.next();
试一试{
if(data.get(key)instanceof JSONArray){
JSONArray arry=data.getJSONArray(key);
int size=arry.length();
对于(int i=0;i
您是如何解析它的?到目前为止您已经尝试了什么。谢谢您的回复。