IOS - JSON数据解析 小3种方法

时间:2024-09-02 22:34:02

[manager GET:serverURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

// 3 解析返回的JSON数据

// 3.1

//        NSDictionary *result1 = (NSDictionary *)responseObject;

// 3.2

//        NSString *requestTmp = [NSString stringWithString:operation.responseString];

//        NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];

//        NSDictionary *result2 = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];

//        NSLog(@"response:%@",responseObject);

// 3.3

NSData *responseData = [NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:nil];

NSDictionary *result3 = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:nil];