JsonReader JSONObject 区别
来源:互联网 发布:端口概念 编辑:程序博客网 时间:2024/06/14 16:41
由于使用了GSON库解析json数据成不同的类。然后就找到了两种方法。不懂那种效率高。有时间还请高人指教。先上代码先。
首先是jsonreader的:
JsonReader reader = new JsonReader(new StringReader(content));
reader.beginObject();
String tagName = reader.nextName();
if (tagName.equals("response_params")) {
while (reader.hasNext()) {
String tag = reader.nextName();
if (tag.equals("appid")) {
appid = reader.nextString();
}else if (tag.equals("channel_id")) {
channelid = reader.nextString();
}else if (tag.equals("user_id")) {
userid = reader.nextString();
} else {
reader.skipValue();//忽略值/跳过break
}
}
}
reader.endObject();
然后是JSONObject 的:
JSONObject jsonContent = new JSONObject(content);
JSONObject params = jsonContent
.getJSONObject("response_params");
appid = params.getString("appid");
channelid = params.getString("channel_id");
userid = params.getString("user_id");
一眼看过去。明显jsonobject简单很多。就是不知道效率怎么样。
- JsonReader JSONObject 区别
- jsonreader
- JsonObject生成Json字符串,并且解析为对象-----JsonReader解析Json字符串
- JSONObject 方法区别
- JSONObject/JSONArray的区别
- JSONObject、JSONArray区别
- jsonObject.getString() 和jsonObject.optString()区别
- Android中JSONObject与JsonObject的区别
- JSONObject中方法的区别
- JsonObject和JsonArray的区别
- JSONArray和JSONObject的区别
- JSONObject与JSONArray的区别
- JSONObject和JSONArray的区别
- JSONObject和JSONArray的区别
- JSONObject optString与getString区别
- Gson转换与JSONObject区别
- JSONArray和JSONObject的区别
- JSONObject和JSONArray的区别
- 第18章 IP协议
- ASP.NET Atlas实现网站模块(版块)拖放(Drag & Drop)效果
- openFire部署配置
- 关于中国天气网API
- 霍夫森林(Hough Forest)目标检测算法
- JsonReader JSONObject 区别
- C.Interface.And.Implementations—memory(简单版本)的实现
- Qt txt文件打开保存
- Tesseract related
- ORACLE 11G透明网关访问SQL2008R2
- No Hibernate Session bound to thread, and configuration does not allow creat
- Linux防火墙的开启和关闭
- iOS之地图和定位应用开发
- C-Dogs for ios