IOS自带json解析类解析json
1 - (IBAction)test:(id)sender { 2 NSString *result = @"{\"code\":\"S00000\",\"message\":\"success\",\"data\":{\"file_name\":\"b1feba4439d0bed9f867123637121b24-dc7764fb24f7294c6a3dcb6971eddb25.png\",\"paths\":[\"x1\",\"x2\",\"x3\",\"x5\",\"x6\",\"x7\",\"x8\",\"xm\"]}}"; 3 NSError *error; 4 NSData* response = [result dataUsingEncoding:NSUTF8StringEncoding]; 5 6 NSDictionary *jsonInfo = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:&error]; 7 NSString *code = [jsonInfo objectForKey:@"code"]; 8 9 NSLog([NSString stringWithFormat:@"%@",code]); 10 11 NSDictionary *data = [jsonInfo objectForKey:@"data"]; 12 NSLog([NSString stringWithFormat:@"%@",[data objectForKey:@"file_name"]]); 13 }
第6行的NSJSONReadingOption是干嘛的没搞明白 用NSJSONReadingMutableLeaves也能正常解析
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。