【问题标题】:'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance'NSInvalidArgumentException',原因:'-[__NSCFString objectAtIndex:]:无法识别的选择器发送到实例
【发布时间】:2016-05-25 10:22:41
【问题描述】:

下面是我的代码

   nameLabel.text=[[[dict_Details objectForKey:@"unknown_object"] objectAtIndex:0] objectForKey:@"UserFullName"];

这是我的回复

getUserReviewsResponse

{
"status_code" = 200;
"unknown_object" = "[{ID:227,ServiceProviderName:Dr.KarthikMendi,UserFullName:karthik,ReviewTemplateID:19,TotalScore:88.0,ServiceName:Doctor,Review:Very knowlegable doctor he understands the problem very well.,ServiceID:5,CommentsBySP:Thank you...,ServiceProviderID:0,CommentByAdmin:null,UserID:106,Status:true,CreatedDate:2016-05-06T18:30:08,Services:null,ServiceProviderTypes:null},{ID:168,ServiceProviderName:Dr.KarthikMendi,UserFullName:karthik,ReviewTemplateID:19,TotalScore:92.0,ServiceName:Doctor,Review:I am very impressed.  Very organized and professional.\\r\\nI always leave feeling taken care of and medical needs met. \\r\\nNeed more Dr\U00e2\U0080\U0099s like him!\\r\\nGreat!  He gave me sufficient time!\\r\\nVery friendly, informed and hospitable. \\r\\nVery nice \U00e2\U0080\U0093 didn\U00e2\U0080\U0099t feel like a number, but an actual person.,ServiceID:5,CommentsBySP:Thank you,ServiceProviderID:0,CommentByAdmin:null,UserID:84,Status:true,CreatedDate:2016-03-23T10:12:19.087,Services:null,ServiceProviderTypes:null}]";
}

【问题讨论】:

  • unknown_object 的值是一个大字符串,而不是字典。
  • 那我现在该怎么办?
  • 如果是 JSON(JSON 中的 JSON 作为字符串),您可能会感兴趣:Parsing JSON Within JSON in Objective-C 的可能重复
  • 字符串似乎是 JSON,但不是因为缺少双引号。您还负责网络服务吗?

标签: ios objective-c json


【解决方案1】:

"unknown_object" 的值是一个字符串,但您假设它是一个字典,因为您在其上调用 objectForKey:。因此例外。

一般来说,我会说 JSON 是“损坏的”,因为它需要双重反序列化,这没什么用处。

【讨论】:

    【解决方案2】:

    请检查http://jsoneditoronline.org/中的json数据是否正确。

    例如:Dr.KarthikMendi 是包含“Dr.KarthikMendi”(双引号或单引号)的字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      相关资源
      最近更新 更多