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也能正常解析