安卓解析中JSON中getString() 和optString()的区别
来源:互联网 发布:软件培训会务准备 编辑:程序博客网 时间:2024/04/19 20:03
ThedifferenceisthatoptSt;这个是在stackoverflow上面看到的;
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.
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会抛出异常。
---------------
可以解决服务器字段缺少或者没有该字段而导致的异常以至于程序崩溃。
0 0
- 安卓解析中JSON中getString() 和optString()的区别
- Json中optString和getString的区别
- JSON中optString和getString的区别
- JSON中optString和getString的区别
- JSON中optString和getString的区别
- JSON中optString()和getString()区别
- 关于JSON中optString和getString的区别
- JSON中getString() 和optString()
- JSON中getString() 和optString()
- JSONObject中optString和getString等的区别
- optString和getString区别
- JSONObject的getString()和optString()的区别
- getString和optString的区别(补充toString和valueOf)
- JsonObject的optString()和getString()的区别
- jsonObject.getString() 和jsonObject.optString()区别
- jsonObject.getString()解析任意字段均可强转为string 及与jsonObject.optString()的区别
- JSONObject optString与getString区别
- 在Json解析过程中,我为什么用object1.optInt ,和 object1.optString
- windows开机后svchost.exe进程占用很大内存,卡机
- 洛谷月赛:最后的狂欢 汽车拉力比赛
- GCM 实现
- PHP 程序员学数据结构与算法之《栈》
- Android USB Host 通信程序
- 安卓解析中JSON中getString() 和optString()的区别
- android图片预览
- CvSVM::EPS_SVR train_auto assertion sv_count != 0 failed原因
- cmd命令行窗口正确显示编码为utf-8格式的文字
- 构造干净的 Git 历史线索
- django 验证用户是否登陆
- ios加载gif图片
- MySQL联合索引
- jQuery Ajax 实例 ($.ajax、$.post、$.get)