I'm a new to iOS.
NSData:
{
"results" : [
{
"formatted_address" : "Proyezd Voskresenskiye Vorota, 3, Moscow, Russia, 109012",
"geometry" : {
"location" : {
"lat" : 55.75622380,
"lng" : 37.61855850
}
I need only "formatted_address", could you help me to make a NSString in which will be address? Sorry for stupid question.
Your NSData
is a JSON response, you need to create an NSDictionary
to be able to access specific portions of the data. An NSDictionary
just maps keys to values. To get the values you call – objectForKey:
. In your case you have a dictionary as a value for the key "results". So in your case:
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSDictionary *resultsDictionary = [[results objectForKey:@"results"] objectAtIndex:0];
NSString *formattedAddress = [resultsDictionary objectForKey:@"formatted_address"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With