打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JSON解析之 getJSONObject 与 optJSONObject 的区别
[代码]JSON解析的两个函数     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//optJSONObject源码解析:
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONObject}. Returns null otherwise.
*/
public JSONObject optJSONObject(String name) {
Object object = opt(name);
return object instanceof JSONObject ? (JSONObject) object : null;
}
//当返回值不是JSONObject对象时,返回值为null,不抛出异常;
//getJSONObject源码解析:
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONObject}.
* @throws JSONException if the mapping doesn't exist or is not a {@code
* JSONObject}.
*/
public JSONObject getJSONObject(String name) throws JSONException {
Object object = get(name);
if (object instanceof JSONObject) {
return (JSONObject) object;
} else {
throw JSON.typeMismatch(name, object, "JSONObject");
}
}
//当返回值不是JSONObject对象时,抛出异常;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
json2.js json.jar - xiejiaohui - JavaEye技术网站
JSON for java入门总结
二级列表demo(ExpandableListView)
json示例
Java服务器端List对象转换为JSON对象并返回客户端实例
如何利用.Net内置类,解析未知复杂Json对象
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服