JSON系統解析:
1,創建請求路徑和URL;
2,根據URL構建請求 ,如果是POST 使用NSMutableURLRequest , NS可變的URL請求;
NSMutableURLRequest *mutableURLRequest = [NSMutableURLRequest requestWithURL:url];
3,構建連接 1、同步 2、異步;
NSData *responseData = [NSURLConnection sendSynchronousRequest:mutableURLRequest returningResponse:nil error:nil];
4,將data轉化為字符串 查看數據的正確性;
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"responseString___%@", responseString);
5,使用系統類解析 1、要解析的數據 2、選項設置 3、錯誤信息;
NSError *error = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSLog(@"dictionary____%@", dictionary);
NSLog(@"%d_______%@", error.code, error.localizedDescription);
新聞熱點
疑難解答