Read the JSON file

Get the File

	//Get file on a background thread to stop GUI locking up
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://mydomain.com/comefile.php"]];    //Could obviously be a .json file too
        [self performSelectorOnMainThread:@selector(fetchedData:)
							   withObject:data waitUntilDone:YES];
    });

 

File Received

//****************************************
//****************************************
//********** JSON FILE RECEIVED **********
//****************************************
//****************************************
- (void)fetchedData:(NSData *)responseData
{
    //Get the json data
    NSError* error;
    NSDictionary* json = [NSJSONSerialization
						  JSONObjectWithData:responseData
						  options:kNilOptions
						  error:&error];
	//View all the data
    NSLog(@"json dump: %@", json);
	
	//Get an individual value
	//NSString *my_value = [json objectForKey:@"my_value"]									//A root value
	NSString *my_value = [[json objectForKey:@"json_results"] objectForKey:@"my_value"];	//A value 1 level deep: $json_data = array("json_results" => array("my_value" => $my_value,...
	NSLog(@"my_value: %@", my_value);
	
	//Get an array
	NSArray* my_array = [[json objectForKey:@"json_results"] objectForKey:@"my_array"];		//$json_data = array("json_results" => array("my_array" => $my_array,...
    NSLog(@"my_array: %@", my_array);
}