0

I'm trying to read data from geojson file using this code:

NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"roads_json" ofType:@"geojson"];

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[[NSData alloc]
                                                              initWithContentsOfFile:jsonPath]
                                                     options:0
                                                       error:nil];
NSLog(@"points:%@",json);

and the output:

points:(null)

any idea plz...

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
Farid
  • 44
  • 1
  • 12

1 Answers1

1

It is always best to pass an NSError object when using NSJSONSerialization. This way you can know what exactly is wrong.

NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[[NSData alloc]
                                                              initWithContentsOfFile:jsonPath]
                                                     options:0
                                                       error:&error];

if (error)
{
    NSLog(@"Could not serialize GeoJSON file: %@", [error localizedDescription]);
}
else
{
    //GeoJSON has been successfully decoded
}
Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
ZeMoon
  • 20,054
  • 5
  • 57
  • 98