I am trying to print MySQL result sets with PHP in JSON format, and read it with iOS.
This is my JSON-string:
[{"partnerid":"1","code":"SUMU6003","partnerName":"Company name","street":"Some Street 5323","zipCode":"8732","city":"Berlin","languages":"English","workers":"Name 1, Name 2","lineup":"Kids"},{"partnerid":"2","code":"DEMO8884","partnerName":"Partner 2","street":"Third street 2","zipCode":"383838","city":"Berlin","languages":"Greek","workers":"Petra","lineup":"Kids"}]
In this method I get the NSDictionary:
#pragma mark - ServiceConnectorDelegate -
-(void)requestReturnedData:(NSData *)data {
NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:data];
# process dictionary and grep strings from json-string
# ...
}
Can you please tell me how to access the different result sets in a loop? I want to access each key separately.
I know that the NSDictionary contains data, because NSLog(@"%@",dictionary); prints:
2012-12-20 19:13:20.661 myapp[576:907] (
{
city = Berlin;
code = SUMU6003;
languages = English;
lineup = Kids;
partnerName = "Company name";
partnerid = 1;
street = "Some Street 5323";
workers = "Name 1, Name 2";
zipCode = 8732;
},
{
city = Berlin;
code = DEMO8884;
languages = Greek;
lineup = Kids;
partnerName = "Partner 2";
partnerid = 2;
street = "Third street 2";
workers = Petra;
zipCode = 383838;
}
)
Thank you very much for the help.
Sometimes introspection can be useful here. For instance NSLog(@”dictionary is of type: %@”, [dictionary class]);
The reason I say that is based on your output it appears that dictionary is in fact an array containing two NSDictionaries. If that is the case you would want to do something like this:
You have to find out what data types your actually dealing with first though.