V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Dystopia
V2EX  ›  iDev

大家都是怎么做「安全锁」的,比如服务器返回 json 每个都要判断是不是为 nil,数据多了好麻烦,有没有更好的办法

  •  
  •   Dystopia · Aug 23, 2016 · 3179 views
    This topic created in 3534 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
    guomiaoyou7784
        1
    guomiaoyou7784  
       Aug 23, 2016
    可以扩展出 dictionary safe 方法。从 json 取用的时候判断对应类型是否需要提供默认值。数据为空引起 crash 是另一码事,代码不够健壮。
    tinyproxy
        2
    tinyproxy  
       Aug 24, 2016 via iPhone
    (°_°)…
    为什么空字符串会导致你的 APP 崩溃。。。
    Rubbly
        3
    Rubbly  
       Aug 24, 2016
    一个 post 请求返回很多 string 数据,感觉这个表达就有问题。
    顺吧请利用好 status code ,而且对于 NULL 也有自己的处理逻辑,与崩溃无关。
    hanxiV2EX
        4
    hanxiV2EX  
       Aug 24, 2016 via iPhone
    用 JSPNRPC 。从底层过滤掉错误数据。
    04BxPLXu2M6UKH6Z
        5
    04BxPLXu2M6UKH6Z  
       Aug 30, 2016 via iPhone
    发消息给 nil 不会 crash 的啊 插入 nil 才会
    ma125125t
        6
    ma125125t  
       Aug 31, 2016
    我一般直接判断字符串的 length
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1139 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 18:12 · PVG 02:12 · LAX 11:12 · JFK 14:12
    ♥ Do have faith in what you're doing.