尝试在Android中获取JSON对象时出错

时间:2013-06-05 17:53:28

标签: android json http getjson endpoint

我有一个具有访问WCF服务的参数的url,该服务读取参数并执行执行返回JSON对象的搜索的方法:

{
"GetUsersByNameMethodResult":[
    {
        "City":"CONTAGEM",
        "Id":11,
        "Name":"Alice"
    },
    {
        "City":"BELO HORIZONTE",
        "Id":7,
        "Name":"Marcia"
    },
    {
        "City":"RIO DE JANEIRO",
        "Id":9,
        "Name":"Marcos"
    },
]

}

这是我在Android中使用的代码:

 // Making HTTP request
    try {
        // defaultHttpClient
        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();
    }

但是在运行上述代码时发生错误时,任何人都知道如何解决这个问题?谢谢。

1 个答案:

答案 0 :(得分:0)

看看这个:Parse this JSON in Android

它有完整的解决方案。只需修改代码以匹配您的json。