在为 iPad 开发时,我创建了一个名为 Coordinates.geojson 的文件。我想从一个名为 JsonDecoder.m 的类文件中访问它
这是 JsonDecoder.m
@implementation JsonDecoder
- (id)initWithJson
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Coordinates" ofType:@"geojson"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error;
_json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
return self;
}
- (NSArray*) getCoordinatesFromShelf:(NSString *) bookShelfName
{
NSArray *coordinates = [[[_json objectForKey:@"shelf1"] objectForKey:@"coordinates"]objectAtIndex:1];
for(id i in coordinates)
NSLog(@"%@",i);
return coordinates;
}
@end
还有我的 Coordinates.geojson:
{
"shelf1": {
"name": "six.png",
"coordinates": [
[
14,
25,
329,
138
],
[
14,
185,
329,
138
],
[
14,
344,
158,
138
],
[
185,
344,
158,
138
],
[
14,
94,
158,
138
],
[
185,
500,
158,
138
]
]
}
}
如何从类文件中检索这些值?
谢谢!