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
  • 22,149
  • 11
  • 88
  • 130
Farid
  • 42
  • 1
  • 11

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
  • 22,149
  • 11
  • 88
  • 130
ZeMoon
  • 18,802
  • 4
  • 52
  • 92