解析JSON字典/数组
如果 JSON Web 服务返回类似这样的内容(房屋的详细信息),
[
{
id:4,
price: 471,
location: "New York",
size: 3000
},
{
id:7,
price: 432,
location: "London",
size: 3200
},
{
id:22,
price: 528,
location: "Tokyo",
size: 2000
}
]
我将如何一一迭代每个房屋?我正在使用 ASIHTTPRequest 和 JSON 解析器: http://stig.github.com/json-framework/
我想我可以像这样获取字典:
NSString *theResponse = [request responseString];
NSDictionary *dictionary = [theResponse JSONValue];
..但我不确定如何迭代每个房子。
If a JSON web service returns something like this (details of houses)
[
{
id:4,
price: 471,
location: "New York",
size: 3000
},
{
id:7,
price: 432,
location: "London",
size: 3200
},
{
id:22,
price: 528,
location: "Tokyo",
size: 2000
}
]
How would I iterate thru each house one-by-one? I'm using ASIHTTPRequest and the JSON parser: http://stig.github.com/json-framework/
I think I can get the dictionary like so:
NSString *theResponse = [request responseString];
NSDictionary *dictionary = [theResponse JSONValue];
.. but I'm unsure how to iterate thru each house.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是字典数组...您可以创建您的 House 的 Modal 类(属性:id,价格,位置,大小)并按如下方式迭代它...(考虑到您最终拥有上述内容)..
谢谢,
This is array of dictionaries... you can create a Modal class of you House(attributed :id,price,location,size) and iterate it as follows...(considering you finally have above thing)..
Thanks,