将JSON转换为NSArray [英] Convert JSON to NSArray
本文介绍了将JSON转换为NSArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在页面上输出了一个JSON数组。我想将此JSON数组转换为NSArray。
I have a JSON array being output on a page. I would like to convert this JSON array into an NSArray.
这是网页上的JSON输出:
[{"city":"Current Location"},{"city":"Anaheim, CA"},{"city":"Los Angeles, CA"},{"city":"San
Diego, CA"},{"city":"San Francisco, CA"},{"city":"Indianapolis, IN"}]
这是我的NSURL电话和NSJSONSerialization:
NSString *cityArrayURL = [NSString stringWithFormat:@"http://site/page.php";
NSData *cityData = [NSData dataWithContentsOfURL:[NSURL URLWithString:cityArrayURL]];
NSError *error;
NSDictionary *cityJSON = [NSJSONSerialization JSONObjectWithData:cityData
options:kNilOptions error:&error];
我想把名为cityJSON的NSDictionary变成NSArray。有人能告诉我下一步可能是什么吗?谢谢!
I would like to turn the NSDictionary called cityJSON into an NSArray. Can someone let me know what the next step might be? Thank you!
推荐答案
这个怎么样?
cityArray = [[NSMutableArray alloc] init];
cityArray = [NSJSONSerialization JSONObjectWithData: cityData options:NSJSONReadingMutableContainers error:nil];
这篇关于将JSON转换为NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文