我正在尝试使用 JSON 格式的 PHP 打印 MySQL 结果集,并使用 iOS 读取它。
这是我的JSON 字符串:
[{"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"}]
在这种方法中,我得到NSDictionary
:
#pragma mark - ServiceConnectorDelegate -
-(void)requestReturnedData:(NSData *)data {
NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:data];
# process dictionary and grep strings from json-string
# ...
}
你能告诉我如何在循环中访问不同的结果集吗?我想分别访问每个键。
我知道NSDictionary
包含数据,因为NSLog(@"%@",dictionary);
打印:
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;
}
)
非常感谢你的帮助。