This topic created in 3617 days ago, the information mentioned may be changed or developed.
如题,大家都是怎么做「安全锁」的,比如服务器返回 json 每个都要判断是不是为 nil ,数据多了好麻烦,有没有更好的办法。
比如,一个 post 请求返回很多 string 数据,有过有数据为空 可能引起 App 崩溃,但当数据很多的时候 if else 判断真的很麻烦,有没有更有效的方法呢?
6 replies • 2016-08-31 14:16:20 +08:00
 |
|
1
guomiaoyou7784 Aug 23, 2016
可以扩展出 dictionary safe 方法。从 json 取用的时候判断对应类型是否需要提供默认值。数据为空引起 crash 是另一码事,代码不够健壮。
|
 |
|
2
tinyproxy Aug 24, 2016 via iPhone
(°_°)… 为什么空字符串会导致你的 APP 崩溃。。。
|
 |
|
3
Rubbly Aug 24, 2016
一个 post 请求返回很多 string 数据,感觉这个表达就有问题。 顺吧请利用好 status code ,而且对于 NULL 也有自己的处理逻辑,与崩溃无关。
|
 |
|
4
hanxiV2EX Aug 24, 2016 via iPhone
用 JSPNRPC 。从底层过滤掉错误数据。
|