2012-09-19 114 views
-4

如何解析android中的以下JSON?json在android中解析

{"Servicedata":{"services_description":"Absolutely awesome compound on 50+ acres","services_image":"http:\/\/192.168.100.81\/watchdog_webservice\/service_images\/shop1.jpg","service_userid":"1"}} 
+0

不要問問題,沒有谷歌它... –

+1

把代碼。讓我們來看看你試圖解析這個JSON ....? –

回答

3
JSONObject object = new JSONObject(yourJsonString); 
JSONObject servicedata = object.getJSONObject("Servicedata"); 
String desc = servicedata.getString("services_description"); 
String image = servicedata.getString("services_image"); 
String id = servicedata.getString("service_userid"); 
+0

thanxxx兄弟你再次幫助我.. N m sry m一個新手:) – Rahulkapil

0

什麼是JSON數據的來源?以下是解析來自URL的JSON。

try { 
     DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpGet httpGet = new HttpGet(url); 

     HttpResponse httpResponse = httpClient.execute(httpGet); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     is = httpEntity.getContent(); 

    } catch (UnsupportedEncodingException e) { 
     e.printStackTrace(); 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    try { 
     BufferedReader reader = new BufferedReader(new InputStreamReader(
       is, "UTF8"), 8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while ((line = reader.readLine()) != null) { 
      sb.append(line + "n"); 
     } 
     is.close(); 
     json = sb.toString(); 
    } catch (Exception e) { 
     Log.e("Buffer Error", "Error converting result " + e.toString()); 
    } 

    try { 
     jObj = new JSONObject(json); 
    } catch (JSONException e) { 
     Log.e("JSON Parser", "Error parsing data " + e.toString()); 
    }