我有从我的网络服务接收json的json。 这将是这样的,
{"JSONDataResult":"[{\"id\":3,\"e_code\":123533,\"type\":\"ab\",\"description\":\"sick-leave\",\"remarks\":\"test\",\"req_date\":\"2016-07-01T12:22:34\",\"date\":\"01\/07\/2016\",\"response\":null,\"aproved_date_time\":null,\"status\":\"not seen\"}]"}
从json http://www.jsoneditoronline.org/验证它时,它说它只有一个对象。我甚至无法将其转换为来自客户端Android应用程序的json数组,就像这样说
org.json.JSONException: Value [{"id":3,"e_code":123533,"type":"ab","description":"sick-leave","remarks":"test","req_date":"2016-07-01T12:22:34","date":"01/07/2016","response":null,"aproved_date_time":null,"status":"not seen"}] at JSONDataResult of type java.lang.String cannot be converted to JSONArray
我使用AsyncHttpClient(loopj)来解析json
client.get("http://192.168.1.6/JSONService/RESTService.svc/json/dddd",new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
try {
String str=response.toString();
JSONObject jobj=new JSONObject(str);
jsonArray=jobj.getJSONArray("JSONDataResult");
...
答案 0 :(得分:0)
您可以通过以下方式解析它:
假设您在下面的变量中得到响应为strData
strData = strData.replaceAll("\\","");
JSONObject jsonObject = new JSONObject(strData);
JSONArray jsonArray = jsonObject.getJSONArray("JSONDataResult");