从 json 字符串获取媒体 url
我如何从这个 json 中获取图像路径+名称?
/*
{
distance = 0;
"effective_from" = "2011-02-19 12:27:20";
"effective_thru" = "2011-02-19 13:27:20";
fname = eric;
latitude = "11.92179";
"listing_id" = 60;
lname = cartman;
longitude = "-74.70189";
lstatus = active;
media = "{\"media\":
[
{\"id\":149,\"media_url\":\"mediauploads/149.jpg\"},
{\"id\":150,\"media_url\":\"mediauploads/150.jpg\"},
{\"id\":151,\"media_url\":\"mediauploads/151.jpg\"},
{\"id\":152,\"media_url\":\"mediauploads/152.jpg\"}
]}";
tags = "Separate multiple tags with commas";
text = "Listing text";
title = "Please provide a descriptive title";
username = eric;
"users_id" = 13;
},
*/
我的问题是 NSDictionary *media = [userContent objectForKey:@"media"];返回 -[NSCFString objectForKey:]: 发送到实例 0x66662a0 的无法识别的选择器,因此我无法从中获取数组。
更新:事实证明我从服务器获取了字符串。我怎样才能将它解析到字典中?
任何帮助表示赞赏。
谢谢!
How would I get the image path+name out of this json?
/*
{
distance = 0;
"effective_from" = "2011-02-19 12:27:20";
"effective_thru" = "2011-02-19 13:27:20";
fname = eric;
latitude = "11.92179";
"listing_id" = 60;
lname = cartman;
longitude = "-74.70189";
lstatus = active;
media = "{\"media\":
[
{\"id\":149,\"media_url\":\"mediauploads/149.jpg\"},
{\"id\":150,\"media_url\":\"mediauploads/150.jpg\"},
{\"id\":151,\"media_url\":\"mediauploads/151.jpg\"},
{\"id\":152,\"media_url\":\"mediauploads/152.jpg\"}
]}";
tags = "Separate multiple tags with commas";
text = "Listing text";
title = "Please provide a descriptive title";
username = eric;
"users_id" = 13;
},
*/
My problem is that NSDictionary *media = [userContent objectForKey:@"media"]; returns a -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x66662a0 so I cannot get the Array out of it.
Update: so it turns out that I get as a string from the server. How can I parse it to a dictionary?
Any help is appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TouchJSON 提供了一个 JSON Deserializer 类,其中包含将 JSON 转换为字典的方法。
如果您以字符串形式返回 JSON,请首先将其转换为 NSData。例如:
然后创建一个 CJSONDeserializer 并传递数据以返回字典:
然后您应该能够从字典中提取所需的数据。
TouchJSON provides a JSON Deserializer class that contains a method to convert JSON to a dictionary.
If you get the JSON back as a string, firstly convert it to NSData. For example:
Then create a CJSONDeserializer and pass the data to return a dictionary:
You should then be able to extract your required data from the dictionary.