【发布时间】:2013-12-13 10:41:08
【问题描述】:
我正在从服务器获取一个 json 数组。 jsonOutput 对象正确显示 2 个对象。但我无法显示或提取数据。有人能帮帮我吗。我试过 以下方式:
for (id key in jsonOutput) {
NSLog(@"key: %@, value: %@", key, [jsonOutput objectForKey:key]);
}
声明: NSDictionary *jsonOutput;
实际方法:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data=[[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[data appendData:theData];
// if ([connection isEquals:connect1]){
// this is request urlConnectionRecsender
// }
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
jsonOutput= [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
for (id key in jsonOutput) {
NSLog(@"key: %@, value: %@", key, [jsonOutput objectForKey:key]);
}
}
【问题讨论】:
-
您可以传入一个错误变量并检查该对象。如果没有错误写入变量,请检查是否有数组或字典。
标签: ios objective-c nsdictionary nsjsonserialization