如何在Xcode中将JSON数组转换为数组?

时间:2012-06-18 07:23:36

标签: xcode arrays json

如何转换此JSON数组:

这是一个序列化的JSON数组

    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);
                }

或者我只想在桌面视图上显示这些项目作为单元格.. 任何人都可以建议一些代码并解释这个....

1 个答案:

答案 0 :(得分:0)

这会将所有国家/地区提取到一个数组中:

NSArray *countries = [myArrayFromJson valueForKey:@"Countries"];

请注意,您的第二个片段是NSDictionary,其中包含一个键(“国家/地区”)和一组值。所以它不只是'阵列'......

所以,如果你真的想这样做,你可以这样做:

// After collecting the values into 'countries' array like above...
NSDictionary *countriesDict = [NSDictionary dictionaryWithObject:countries forKey:@"Countries"];