구문 분석하는 동안 약간 혼란스러운 JSON 데이터를 구문 분석 할 수 없습니다. 여러 가지 방법으로 시도했지만 그렇게 할 수 없습니다. JSON 구문 분석을 처음 사용합니다. 누구든지 나를 도울 수 있습니까?
{
"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의 응답으로 받고 있습니다.
감사.
이 재귀 함수를 사용해보십시오
이 함수를 호출하고 logcat을 확인하십시오.
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();
}
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다