0

我正在使用 JSON 网络服务。首先,我将值保存在服务器上,然后获取相同的值。当我点击 API 或 url 时,我在插入值期间留空的字段显示 0 值。它正在获取显示在控制台中的数组,但未显示在标签、按钮等上。它正在杀死错误[NSDecimalNumber length]。我想知道这里出了什么问题,以及那些在插入过程中留空的标签返回了什么。以及如何检测标签具有零值或空值。以及如何处理它们。

我在这里发布 JSON

{
   "messageshow":[
      {
         "message_id":"502",
         "message":"http://flut.psites.info/api/messages/voice/1360100571.caff",
         "message_pic":"",
         "uid":"44",
         "created":"14 second ago",
         "username":"pari",
         "first_name":"pp",
         "last_name":"pp",
         "profile_pic":"http://flut.p-sites.info/api/uploads/13599968121.jpg",
         "tag_user":{
            "tags":[
               {
                  "message":"false"
               }
            ]
         },
         "boos_list":{
            "booslist":[
               {
                  "message":"false"
               }
            ]
         },
         "aplouds_list":{
            "aploudslist":[
               {
                  "message":"false"
               }
            ]
         },
         "total_comments":0,
         "total_boos":0,
         "total_applouds":0
      },
      {
         "message_id":"501",
         "message":"http://flut.psites.info/api/messages/voice/1360100045.caff",
         "message_pic":"",
         "uid":"44",
         "created":"9 minutes ago",
         "username":"pari",
         "first_name":"pp",
         "last_name":"pp",
         "profile_pic":"http://flut.psites.info/api/uploads/13599968121.jpg",
         "tag_user":{
            "tags":[
               {
                  "message":"false"
               }
            ]
         },
         "boos_list":{
            "booslist":[
               {
                  "message":"false"
               }
            ]
         },
         "aplouds_list":{
            "aploudslist":[
               {
                  "message":"false"
               }
            ]
         },
         "total_comments":0,
         "total_boos":0,
         "total_applouds":0
      },
      {
         "message_id":"500",
         "message":"http://flut.p.info/api/messages/voice/1360099970.caff",
         "message_pic":"",
         "uid":"44",
         "created":"10 minutes ago",
         "username":"pari",
         "first_name":"pp",
         "last_name":"pp",
         "profile_pic":"http://flutpsites.info/api/uploads/13599968121.jpg",
         "tag_user":{
            "tags":[
               {
                  "message":"false"
               }
            ]
         },
         "boos_list":{
            "booslist":[
               {
                  "message":"false"
               }
            ]
         },
         "aplouds_list":{
            "aploudslist":[
               {
                  "message":"false"
               }
            ]
         },
         "total_comments":0,
         "total_boos":0,
         "total_applouds":0
      }
   ]
}
4

1 回答 1

0

First: What are you using to parse the received JSON data? NSJSONSerialization, JSONKit, ...?

Second: I guess that you try to call -length on a value from the parsed JSON data. But because that value is empty (0) it get's parsed into a NSNumber instead of a string. NSNumber doesn't implement a -length method and your app crashes.

You should return null or an empty string in your JSON for empty string values and not just 0.

P.S.: Don't use NSDecimalNumber, but NSNumber instead. NSDecimalNumber is meant for performing calculations and not to wrap integers.

于 2013-02-05T15:34:17.863 回答