Android 앱에서 웹 서비스를 사용하고 있습니다. 앱에서 다음 응답을 구문 분석 할 수 없습니다. 그것은 항상 준다
org.json.JSONException : 값 [{ "METER_READING": "15", "UTILITY_PLAN": "1", "uname": "[email protected]", "kwh_usage": "3", "meter_reading_date": " 02-13-2014 ","ESID ":"abc ","METER_ID ":"abc100 "}] 유형 java.lang.String 데이터는 JSONArray로 변환 할 수 없습니다.
아래는 내 코드입니다.
StringEntity entity = new StringEntity(jsonObject.toString(), HTTP.UTF_8);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
BufferedReader reader =new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String jsonResultStr = reader.readLine();
JSONObject jObject = new JSONObject(jsonResultStr);
JSONArray jArray = jObject.optJSONArray("data");
웹 서비스에서 다음과 같은 응답을받습니다.
{ "data": "[{\"METER_READING \ ": \"25 \ ", \"UTILITY_PLAN \ ": \"1 \ ", \"uname \ ": \"[email protected] \ ", \" kwh_usage \ ": \"9 \ ", \"meter_reading_date \ ": \"02-13-2014 \ ", \"ESID \ ": \"abc \ ", \"METER_ID \ ": \"abc100 \ "} ] "}
다음과 같은 것을 사용해보십시오.
jsonResultStr = jsonResultStr.replace( "\\", "" ).replaceAll( "\"\\[", "[" ).replaceAll( "\\]\"", "]" );
JSONObject jObject = new JSONObject(jsonResultStr);
JSONArray jArray = jObject.optJSONArray("data");
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다