您的位置:首页 > 移动开发 > Objective-C

JSONObject的getString()和optString()的区别

2015-08-04 15:33 771 查看
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.

这个是在stackoverflow上面看到的,mark一下,简单来说就是optString会在得不到你想要的值时候返回空字符串”“,而getString会抛出异常。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: