JSON中get()和opt()的区别
2016-02-23 11:45
417 查看
get()取值不正确会抛出异常,必须用try catch或者throw包起
而opt()取值不正确则会试图进行转化或者输出友好值,不会抛出异常
Get an optional value associated with a key.
Parameters:
Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not
Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
而opt()取值不正确则会试图进行转化或者输出友好值,不会抛出异常
opt
public java.lang.Object opt(java.lang.String key)
Get an optional value associated with a key.
Parameters:
key- A key string.Returns:An object which is the value, or null if there is no value.
optDouble
public double optDouble(java.lang.String key)
Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
optBoolean
public boolean optBoolean(java.lang.String key)
Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not
optInt
public int optInt(java.lang.String key)
Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
相关文章推荐
- JavaScript添加随滚动条滚动窗体的方法
- 理解javascript定时器中的单线程
- Javascript调用C#后台方法及JSon解析
- jsoup是如何选择指定元素的
- javascript 小白学习指南专题 作用域与上下文环境之间的联系
- JavaScript NaN 属性
- Extjs模型类的声明与实例化和调用
- javascript每日必学之多态
- js创建对象的6种方式
- js传真实地址 C:\fakepath
- js的闭包
- javascript每日必学之继承
- 高性能javascript
- JS实现的仿QQ空间图片弹出效果代码
- js获得桌面size
- Ext JS 5.1.0 Grid的deselect事件失效的处理方法
- 彻底理解js中this的指向
- 无废话ExtJs 入门教程十七[列表:GridPanel]
- javascript 小白学习指南专题 -- 执行上下文 执行上下文栈
- ZK 最少限度加载页面js文件