for (NSDictionary *result in results) {
NSString *name = [result objectForKey:@"name"];
NSString *images=[result objectForKey:@"img"];
NSLog(@"%@", name);
NSLog(@"%@",images);
displayApiLabel.text=[NSString stringWithFormat:@"%@",name];
NSData *convertData=[images dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@",convertData);
UIImage *img=[UIImage imageWithData:convertData];
NSLog(@"sads%@",img);
}
我有一个问题,通过json url字符串在ios中显示图像和名称是否有任何人帮我解决它在此先感谢
json return
{"DATA":[
{"id":"1","name":"Fast Food","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410258775_58_fast-food.png"},
{"id":"2","name":"Chinese","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410259648_28_chinees.png"},
{"id":"3","name":"Drinks","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410259679_67_drinks.png"},
{"id":"4","name":"Icecream","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410259705_34_icecream.png"},
{"id":"5","name":"Continental","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410259737_53_master_icon.png"},
{"id":"6","name":"Starter","img":"http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410592310_18_starter.png"}
],
"STATUS":{"X_STATUS_REQUEST":1,"X_STATUS_ERROR_CODE":0,"X_STATUS_ERROR_DESC":""}
}
答案 0 :(得分:0)
试试这个
NSDictionary *finalres = [result objectForKey:@"DATA"];
for (NSDictionary * finalres in results) {
NSString *name = [finalres objectForKey:@"name"];
NSString *images=[finalres objectForKey:@"img"];
NSLog(@"%@", name);
NSLog(@"%@",images);
displayApiLabel.text=[NSString stringWithFormat:@"%@",name];
NSData *convertData=[images dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@",convertData);
UIImage *img=[UIImage imageWithData:convertData];
NSLog(@"sads%@",img);
}
答案 1 :(得分:0)
2015-01-19 17:22:07.571 smartwok [1342:60b]连接成功
2015-01-19 17:22:07.664 smartwok [1342:60b] didReceiveResponse
2015-01-19 17:22:07.664 smartwok [1342:60b] connectionDidFinishLoading
2015-01-19 17:22:07.665 smartwok [1342:60b]成功!收到943字节的数据
2015-01-19 17:22:07.665 smartwok [1342:60b]快餐
2015-01-19 17:22:07.665 smartwok [1342:60b] http%3A%2F%2F10.0.0.131%2Fcafe_management%2Fmenu%2Fimages%2Fmaster_category%2F1410258775_58_fast-food.png
2015年1月19日17:22:07.666 smartwok [1342:60B] LT; 68747470 3a2f2f31 302e302e 302e3133 312f6361 66655f6d 616e6167 656d656e 742f6d65 6e752f69 6d616765 732f6d61 73746572 5f636174 65676f72 792f3134 31303235 38373735 66617374 5f35385f 2d666f6f 642e706e 67>
2015-01-19 17:22:07.709 smartwok [1342:60b] sads(null)
它不能正常工作