u014297278
松鼠大作战
2015-09-24 02:14
采纳率: 66.7%
浏览 2.5k

ios关于用json转字典问题 ,请教

NSString *string1=@"{\"code\":\"1\",\"desc\":[{\"col_0007\":\"李玉华\", \"col_0023\":\"已回单\",\"col_0025\":\"800.00\", \"col_0027\":\"T14101400008\",\"col_0031\":\"2014-10-14 22:21:05\", \"col_0042\":\"null\",\"col_0057\":\"null\"},{\"col_0007\":\"李丽\", \"col_0023\":\"已转单\",\"col_0025\":\"0.00\", \"col_0027\":\"T14101400009\",\"col_0031\":\"2014-10-14 22:33:49\", \"col_0042\":\"null\",\"col_0057\":\"null\"}]}";

dicRoot = [[[SBJsonParser alloc]init] objectWithString:string1];
NSString *desc2 =[dicRoot objectForKey:@"desc"];

NSDictionary *dicRoot2 = [[[SBJsonParser alloc]init] objectWithString:desc2];
NSLog(@"sucahkshdkahskdjh: %@", dicRoot2);

    报错 新手求教Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM dataUsingEncoding:]: unrecognized selector sent to instance 0x7a731320'
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • Leexianke
    Leexianke 2015-09-24 03:49
    已采纳

    [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonErr]这个解析会比较好

    点赞 评论
  • u014297278
    松鼠大作战 2015-09-24 02:25

    汪汪汪汪汪!~~~~~!!!!!!!!

    点赞 评论
  • Leexianke
    Leexianke 2015-09-24 03:49

    [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonErr]这个解析会比较好

    点赞 评论
  • majinyu888
    Harbin-Fish 2015-09-24 06:58
    • (id)dictionaryOrArrayWithJSONSString:(NSString *)jsonString

      {

      if (jsonString ==nil)

      {

      return nil;

      }

      NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

      return [NSJSONSerializationJSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves|NSJSONReadingMutableContainers error:nil];

      }

    点赞 评论

相关推荐