-4

如何在android中解析以下JSON?

{"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"}}
4

2 回答 2

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");
于 2012-09-19T10:22:40.717 回答
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());
    }
于 2012-09-19T10:22:22.947 回答