我遇到了一个听起来很容易解决的问题,但我并不十分清楚。
我从我的网络服务收到Json
this url
。您将看到我有一个名为“messages”的JsonArray对象:
{"status":"200",
"messages":[
{"Id":"3",
"Titel":"Test",
"Bericht":"Test",
"Datum":"2014-07-10 0:45:12"},
{...}
]
}"
我让Android解析这个接收到的上下文,但显然数组“messages”以某种方式转换为assoc数组:
{"status":"200",
"messages":[
{"2":
{"Id":"3",
"Titel":"Test",
"Bericht":"Test",
"Datum":"2014-07-10 0:45:12"}
},
{"3": {...}}
]
}"
这是我接收json字符串的方式:
// appending params to url
if (params != null) {
String urlParams = "";
for(NameValuePair param : params) {
urlParams += "/" + URLEncoder.encode(param.getName(), "UTF-8") + "/";
urlParams += URLEncoder.encode(param.getValue(), "UTF-8");
}
url += urlParams.replace("+", "%20");
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
return EntityUtils.toString(httpEntity);
返回值是上面的第一个json。知道为什么会这样吗?我假设Android没有将接收到的内容解释为Json,因此我不知道如何将数组转换为assoc数组。