Newbie question(get data from array)

578
1
03-21-2012 12:38 PM
VladislavZagorodnyuk
New Contributor
I have some code where i using yajl parser:

NSArray *JSONArray = [tempContainer yajl_JSON];
NSLog(@"array of json is = %@",JSONArray);

and after parsing i got some json data like
{
account_number"account_number": "123",
some_stuff"some_stuff": 231,
}

My question is next: how i get data from specific value of parsed data.

ex. i want "account_number" , and i get "123"
0 Kudos
1 Reply
JeffPapirtis
New Contributor III
instead of an array you should start with poplating your JSON String into a Dictionary.  Then retrieve the Key Value pair that you need.

Define a few Arrays in your .h

NSArray *_layerArray;
    NSArray *_keys;
    NSArray *_name;

and in my .m in viewDidLoad

//Define your Service
    NSURL *_serviceURL = [NSURL URLWithString:@"http://"YourService"=json&pretty=true"];
   
    //Create a string to read into your Dictionary
    NSString *_layerNames = [[NSString alloc] initWithContentsOfURL:_serviceURL encoding:NSASCIIStringEncoding error:NULL];
   
    //Create a Dictionary for your jsonValues
    NSMutableDictionary* jSonDict = [_layerNames AGSJSONValue];
   
    //Create an array for a specific Key Value Pair Layers are the array in the JSON String that I want to get.
    _keys = [jSonDict valueForKey:@"layers"];
   
    //NSLog(@"Dictionary %@",_keys);
   
    //Create an Array from your Array of Keys to get ther Values, Name is the key for the Value that I want.
    _name = [[_keys valueForKey:@"name"] copy];

Hope this helps you out.
0 Kudos