JSON中get和opt的区别
答案:2 悬赏:50 手机版
解决时间 2021-04-03 21:28
- 提问者网友:寂寞梧桐
- 2021-04-03 17:32
JSON中get和opt的区别
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-04-03 18:01
get()取值不正确会抛出异常,必须用try catch或者throw包起
而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.
而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.
全部回答
- 1楼网友:痴妹与他
- 2021-04-03 19:37
应该是post吧,这个是两种请求的区别,跟json没关系的
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯