2011-08-18 71 views
0

如何這個JSON數據在Android的解碼我reied下面的代碼的Android解碼JSON數據

[ 
    {"data": 
     {"url": 
     { 
     "url": "http://www.xxxxxx.com/story.html", "title":"some data","source_url": "www.somesite.com", "summary": "\n \n \n \n \n somedata again" 
     } 
     } 
    } 
] 

Java代碼

EDIT:

HttpPost post = new HttpPost(postURL); 
    MultipartEntity reqEntity = new MultipartEntity(); 

    HttpResponse response = client.execute(post); 
    HttpEntity resEntity = response.getEntity(); 




    String r1 = EntityUtils.toString(resEntity); 
    System.out.println("printing response now "+r1); 


    //Toast.makeText(getApplicationContext(), "data received"+r1, Toast.LENGTH_LONG).show(); 
    JSONObject json = new JSONObject(r1); 
    JSONArray venues = json.getJSONObject("data") 
       .getJSONArray("url") 
       .getJSONObject(0) 
       .getJSONArray("url"); 

    Toast.makeText(getApplicationContext(), "data received"+venues, Toast.LENGTH_LONG).show(); 

回答

1

如果金星應該是URL本身,代碼應該是:

JSONArray json = new JSONArray(r1); 
String venues = json.getJSONObject(0) 
       .getJSONObject("data") 
       .getJSONObject("url") 
       .getString("url"); 
+0

沒有這個工作getJSONObject在這種情況下給出了一個錯誤 – Rajeev

+0

我的錯誤,請參閱編輯。 – MByD

+0

我得到一個異常爲08-18 14:35:51.806:INFO/System.out(935):Exceptionorg.json.JSONException:值java.lang.String類型的<!DOCTYPE不能轉換爲JSONArray – Rajeev