2012-09-19 9 views
-4

Как разобрать следующий JSON в Android?json parsing in 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

Не задавайте вопросы без Google это ... –

+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 bro помог мне снова .. n m sry m a newbiee :) – Rahulkapil

0

Что является источником данных JSON? Ниже приведен синтаксический анализ JSON из URL.

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()); 
    }