JSON中optString()和getString()区别
2017-05-08 14:28
435 查看
The difference is that
the empty string (
if the key you specify doesn't exist.
the other hand throws a
Use
it's an error for the data to be missing, or
you're not sure if it will be there.
简而言之:optString对应的key中值不存在返回空字符串”“或者是你指定的默认值,而getString会抛出JSONException异常。
optStringreturns
the empty string (
"")
if the key you specify doesn't exist.
getStringon
the other hand throws a
JSONException.
Use
getStringif
it's an error for the data to be missing, or
optStringif
you're not sure if it will be there.
简而言之:optString对应的key中值不存在返回空字符串”“或者是你指定的默认值,而getString会抛出JSONException异常。
相关文章推荐
- JSONObject的getString()和optString()的区别
- jsonObject.getString()解析任意字段均可强转为string 及与jsonObject.optString()的区别
- JsonObject的optString()和getString()的区别
- Json中optString和getString的区别
- 关于JSON中optString和getString的区别
- 2014-12-03:hibernate get()与load()区别,json字符串转换为json对象,String与date相互转换
- JSONobject.getString()和JSONobject.optString()
- JSON中optString和getString的区别
- JSON中optString和getString的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- WritePrivateProfileString与GetPrivateProfileString用法与区别
- istream::get,getline函数与string getline区别 istream::read 和ostream::write
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- HttpServletRequest.getParameter(String)和getAttribute(String)的区别
- 关于JSONP与UWA.DATA.getJson的区别
- Runtime.getRuntime.exec(String)与exec(String[])的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- struts2.1、struts2.3 getJson区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别