i am new programmer.i am using Google Matrix API. i get the following response i wants fetch "text" : "1686 km". i am using Json Parsing. Thanks
"destination_addresses" : [ "San Francisco, Californie, États-Unis" ],
"origin_addresses" : [ "Vancouver, BC, Canada" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 686 km",
"value" : 1685690
},
"duration" : {
"text" : "3 jours 21 heures",
"value" : 336418
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
SBJsonParser *json = [[SBJsonParser new] autorelease];
NSError *jsonError;
parsedJSON = [json objectWithString:data error:&jsonError];
Well, parsedJSON
will be an NSDictionary
so:
NSArray *rows = [parsedJSON objectForKey:@"rows"];
for (NSDictionary *row in rows) {
NSArray *elements = [row objectForKey:@"elements"];
for (NSDictionary *element in elements) {
NSDictionary *distance = [element objectForKey:@"distance"];
NSString *kmDistance = [distance objectForKey:@"text"]; ///< That's what you wanted
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.