JSONObject的getString()和optString()的区别
2015-08-04 15:33
771 查看
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.
这个是在stackoverflow上面看到的,mark一下,简单来说就是optString会在得不到你想要的值时候返回空字符串”“,而getString会抛出异常。
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.
这个是在stackoverflow上面看到的,mark一下,简单来说就是optString会在得不到你想要的值时候返回空字符串”“,而getString会抛出异常。
相关文章推荐
- *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from o
- Objective-C学习- 字符串类型 NSString 和 NSMutableString
- Objective-C学习- 数字对象 NSNumber
- Objective-C学习-数组 NSArray 和 NSMutableArray
- Objective-C学习- 便利初始化函数和便利构造器
- Object-c 典型的单例写法
- Objective-C ARC单例模式
- Objective-C学习笔记_内存管理(二)
- objective-c面向对象
- Objective-C学习笔记_内存管理(一)
- 【iOS开发之Objective-C】协议和代理
- Objective-C 多参数成员函数【好文收藏】
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- objective-c中数组输出对象怎么为地址
- Object-c中对于NSSting类的方法总结
- objective-c中的方法重载
- Object 体系结构常用方法
- Objective C: NSArray的基本用法(Foundation框架详解第一讲)
- Objective-C中的一些特殊的数据类型
- Objective C程序 block代码块 和property协议及Foundation框架