ios - 如何从 iOS 中的 JSON 响应中提取图像

标签 ios json web-services parsing

我正在从 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/

相关文章:

iphone - 使用 UIAppearance 方法自定义 UIAlertView

iphone - 核心数据的预填充版本?

json - 使用 Powershell 从 JSON 选择特定关键字值

java - 服务接口(interface)没有端点! "Error"

java - Jersey Web 服务中的 JSON 数据未正确传输

ios - init! 的目的是什么?失败的初始化器?

ios - 如何获取选中的TabBar项目?

ios决定是否在客户端代码的某些条件下静音我的远程通知,而不是设置内容可用

python - Python 中的 JSON GET 和 POST

c# - 在 sql server 中调用 Web 服务