如何在Xcode中将JSON数组转换为数组?
如何转换此JSON数组: 这是一个序列化的JSON数组如何在Xcode中将JSON数组转换为数组?,xcode,arrays,json,Xcode,Arrays,Json,如何转换此JSON数组: 这是一个序列化的JSON数组 2012-06-18 09:22:07.647 TableView[468:f803] ( { "Countries" = Iceland; "id"=9046567; "name"=abceeeffdsg; }, {
2012-06-18 09:22:07.647 TableView[468:f803] (
{
"Countries" = Iceland;
"id"=9046567;
"name"=abceeeffdsg;
},
{
"Countries" = Greenland;
"id"=3524695;
"name"=gsfjgfsethju;
},
{
"Countries" = Switzerland;
"id"=4613583;
"name"=hdfkdgs;
)
但我需要将此数组转换为以下数组:
{
NSArray* Countries = (
Iceland,
Greenland,
Switzerland,
);
NSArray *id=(9046567,3524695,4613583 );
NSArray * name=(abceeeffdsg,gsfjgfsethju,hdfkdgs);
}
或者,我只是想在我的表视图中将这些项目显示为单元格。。
任何人都可以建议一些代码并解释这一点 这将把所有国家/地区纳入一个数组:
NSArray *countries = [myArrayFromJson valueForKey:@"Countries"];
请注意,您的第二个代码片段是一个带有一个键(“国家”)和一个值数组的NSDictionary
。所以它不仅仅是一个数组
所以,如果你真的想这样做,你可以:
// After collecting the values into 'countries' array like above...
NSDictionary *countriesDict = [NSDictionary dictionaryWithObject:countries forKey:@"Countries"];
您忘记发布JSON数组…这不是有效的JSON,更不用说不是数组;)请参阅线程获取JSON序列化如果我将其转换为数组和NSLog国家/地区数组我得到了这个2012-06-18 10:06:27.246 TableView[841:f803](null)我刚刚测试过它,工作正常。。。你能发布一段实际代码吗?(你如何得到你的第一个阵列,并试图采摘国家)它的工作很好。我只是犯了个错误。我在序列化之前转换为数组。现在它起作用了。谢谢!