我想从 Web 服务中检索 JSON 并对其进行解析。
我走对了吗?
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
// parsing JSON
}
} catch (Exception e) {
}
不幸的是,我不知道如何转换HttpEntity
成 JSONObject。
这是我的 JSON(摘录):
{
"names": [
{
"name": "Zachary"
},
{
"name": "Wyatt"
},
{
"name": "William"
}
]
}