我正在从 web 服务解析 JSON,它给我图像、文本等。可以提取文本,但如何从中提取图像?
这就是 JSON 响应的样子。
[
{ "photo": "23_841676772.jpg",
"date": "2013-06-06 08:11:15",
"tags": "",
"ID_article": "1",
"commentcount": "5"
},
]
我试图在 tableView:cellForRow 方法中这样设置它,但它不起作用。
NSMutableDictionary *tempDict3 = [self.jsonArray objectAtIndex:indexPath.row];
cell.blogImageView.image = [UIImage imageNamed:[tempDict3 objectForKey:@"photo"]];
最佳答案
我使用的是静态 json,您可以将 str 替换为您的 json url。
NSString *Str =[NSString stringWithFormat:@"[{\"photo\": \"23_841676772.jpg\",\"date\":\"2013-06-06 08:11:15\",\"tags\": \"\",\"ID_article\": \"1\",\"commentcount\": \"5\"},{\"photo\": \"dfdgfdgd.jpg\",\"date\":\"2013-06-06 08:11:15\",\"tags\": \"\",\"ID_article\": \"1\",\"commentcount\": \"5\"}]"];
NSDictionary *catgDict = [NSJSONSerialization JSONObjectWithData:[Str dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
for(NSDictionary *dict in catgDict)
{
NSLog(@"dd: %@",dict);
NSLog(@"Photo: %@",[dict valueForKey:@"photo"]);
}
关于ios - 如何从 iOS 中的 JSON 响应中提取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20759844/