Pregunta

I've currently got an NSDictionary that i'm using to store json information in, the JSON is originally serialized into an NSMutuable array and i then assign it to an NSDictionary.

In my annotation method ( a method i'm using to add mkannotations to my map view)i'm trying to loop through the dictionary and add an annotation via co-ordinates stored as a key for each object in the dictionary.

My current results seem to only create one annotation view (pin on the map), looking via break points it seems to be looping through the dictionary but not accessing all the objects, my code is as follows:

for (NSString* key in [[Global sharedglobal]jsonDictionary]) {

NSNumber *longtitude = [[[Global sharedglobal]jsonDictionary] objectForKey:@"v_lon"];
NSNumber *latitude = [[[Global sharedglobal]jsonDictionary] objectForKey:@"v_lat"];
} 

Looking that i'm thinking key in the for argument should refer to a key in one of the objects in the dictionary e.g. @"v_lon", does that seem correct?

Thanks

¿Fue útil?

Solución

OK as i'm new to programming i hadn't fully understood the way the json was being parsed. It works as follows:

The json is one large array with objects containing various data.

The json is downloaded and is stored in an NSMutable array "jsonArray".

To access the objects i needed to use a "for in loop" checking against dictionaries as that is the way the data is now stored in the mutable array. So:

for (NSDictionary *dict in jsonArray){
NSNumber *longtitude = [dict objectForKet:@"keyForLongtitudeEntry"];
}

This will iterate through all objects of dictionary type and set that longtitude variable to the objects current value for the key specified in this case "keyForLongtitudeEntry".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top