2016-07-08 137 views
0

我有從我的web服務接收json的json。 這將是這個樣子,無法解析json在android

{"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/驗證時,它說,它只有一個對象。我甚至不能將其轉換成JSON數組從客戶端的Android應用程序,它說這樣

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(循環J)來解析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"); 

        ... 
+1

抱歉,這是[this]的重複問題(http://stackoverflow.com/questions/15945394/android-value-of-type-java-lang-string-cannot-be-converted-to-jsonarray) – noushad

+0

爲什麼你想將json再次轉換爲字符串嗎?你爲什麼不直接解析它? – SripadRaj

+0

我在那裏找到答案... – noushad

回答

0

您可以通過以下方式對其進行分析:

比方說,你所得到的反應在以下變量strData是

strData = strData.replaceAll("\\",""); 

    JSONObject jsonObject = new JSONObject(strData); 
    JSONArray jsonArray = jsonObject.getJSONArray("JSONDataResult"); 
+0

任何方式謝謝你的回答......得到了答案之前:) – noushad

+0

是的,我看到沒有問題享受你的編碼... – Vickyexpert

+0

這將只是摧毀JSON。餿主意。 – Biffen