[objective-c]jsonを読み込む

jsonを読み込む

NSString*url = @"/php/45/";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSData *json_raw_data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json = [[NSString alloc] initWithData:json_raw_data encoding:NSUTF8StringEncoding];
NSData *json_data = [json dataUsingEncoding:NSUnicodeStringEncoding];
NSError *error=nil;
id data = [NSJSONSerialization JSONObjectWithData:json_data options:NSJSONReadingAllowFragments error:&error];
if (error) {
    NSLog(@"---error code:%d %@",error.code,[error localizedDescription]);
}else{
    if( [data isKindOfClass:[NSArray class]] ){
        NSLog(@"---array");
        
    }else if( [data isKindOfClass:[NSDictionary class]] ){
        NSLog(@"---dic");
    }
}