当前位置: 代码迷 >> JavaScript >> JSON中getString() 跟optString()
  详细解决方案

JSON中getString() 跟optString()

热度:755   发布时间:2013-12-28 22:19:33.0
JSON中getString() 和optString()

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会抛出异常。

?

?

[转载]:http://blog.csdn.net/xuewater/article/details/17221681

  相关解决方案