您的位置:首页 > Web前端 > JavaScript

JSON中optString()和getString()区别

2017-05-08 14:28 435 查看
The difference is that 
optString
 returns
the empty string (
""
)
if the key you specify doesn't exist.
getString
 on
the other hand throws a 
JSONException
.
Use 
getString
 if
it's an error for the data to be missing, or 
optString
 if
you're not sure if it will be there.

简而言之:optString对应的key中值不存在返回空字符串”“或者是你指定的默认值,而getString会抛出JSONException异常。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: