-5

I have database (linkP)

How can I parse the all data from the above link and display the result

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
  • have a look here http://stackoverflow.com/questions/5547311/how-do-i-parse-json-with-objective-c – Works On Mine Feb 03 '14 at 06:39
  • 2
    Use NSURLConnection and NSJSONSerialization. (Also check NSData class) – Midhun MP Feb 03 '14 at 06:40
  • possible duplicate of [How to parsing JSON object in iPhone SDK (XCode) using JSON-Framework](http://stackoverflow.com/questions/3165290/how-to-parsing-json-object-in-iphone-sdk-xcode-using-json-framework) –  Feb 03 '14 at 06:40
  • @user3264750 A question really should show an attempt and ask for help if there are problems. – zaph Feb 03 '14 at 07:16

2 Answers2

2
- (void)viewDidLoad
{
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://arproject.site90.com/jsonbuilding.php"]];

    [request setHTTPMethod:@"GET"];

    [request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];

    NSError *err;
    NSURLResponse *response;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

    NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];

    NSArray *array=[jsonArray objectForKey:@"result"];

    for (int i=0; i<[array count]; i++) {
        NSLog(@"the building id==%@",[[array objectAtIndex:i]objectForKey:@"building_id"]);
        NSLog(@"the building name==%@",[[array objectAtIndex:i]objectForKey:@"building_name"]);
        NSLog(@"the latitude==%@",[[array objectAtIndex:i]objectForKey:@"latitude"]);
         NSLog(@"the longitude==%@",[[array objectAtIndex:i]objectForKey:@"longitude"]);
         NSLog(@"the picture==%@",[[array objectAtIndex:i]objectForKey:@"picture"]);
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
1
dispatch_async(kBgQueue, ^{

    NSURL *myURL = [NSURL URLWithString:@"http://arproject.site90.com/jsonbuilding.php"];
    NSData *data=[NSData dataWithContentsOfURL:myURL];
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});

-(void)fetchedData : (NSData*)responseData
{
      NSError *error;

//parsing json data


 NSMutableArray *dataArray;
 NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

if(error == nil)
{

    dataArray =[dictionary valueForKey:@"result"];

  for (int i=0; i<[dataArray count]; i++)
  {
    NSLog(@"%@",dataArray);
   } 

}
if(error)
NSLog(@"Error is %@",[error localizedDescription]);
}
Mohit
  • 3,708
  • 2
  • 27
  • 30