【发布时间】:2011-09-20 15:31:49
【问题描述】:
您好,我想通过添加新对象来更新现有的 json 数组。如何在 Android 中做到这一点。
我的 json 位于远程机器上,我正在使用 GSON 解析 JSON。
提前致谢
【问题讨论】:
您好,我想通过添加新对象来更新现有的 json 数组。如何在 Android 中做到这一点。
我的 json 位于远程机器上,我正在使用 GSON 解析 JSON。
提前致谢
【问题讨论】:
DefaultHttpClient client = new DefaultHttpClient();
String finalJson="";
HttpGet getRequest = new HttpGet(url);
try {
HttpResponse getResponse = client.execute(getRequest);
final int statusCode = getResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
return null;
}
HttpEntity getResponseEntity = getResponse.getEntity();
finalJson=EntityUtils.toString(getResponseEntity);
System.out.println("getResponse.."+s);
}
catch (IOException e) {
getRequest.abort();
Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
}
finalJson=finalJson.substring(source.indexOf("[")+1)+"\"object:\"" ; // your logic to append object
Gson gson = new Gson();
parseJsonClass response = gson.fromJson(source, parseJsonClass .class);
希望你能明白我的意思
【讨论】: