Only iOS 7 crash [NSNull intValue]: unrecognized selector sent to instance

前端 未结 4 1232
情话喂你
情话喂你 2021-02-03 11:45

I want to get data from JSON service. Only iOS 7 version crash when get data from JSON value. It returns from JSON service below that:

{
    voteAverageRating =         


        
4条回答
  •  感情败类
    2021-02-03 12:08

    That's quite normal. JSON can send null values to your app. If it does, then this is done intentionally by the server and it expects you to handle it. Figure out what the correct behaviour is when a null value is received. Then when you get an object that could be a null value, check

    if (object == [NSNull null])
    {
        // stuff to handle null objects
    }
    else
    {
        // stuff to handle non-null objects
    }
    

    The real problem isn't that your app crashes, but that your app doesn't handle JSON data that it is supposed to handle.

提交回复
热议问题