-1

我已经解析了 json 字符串,然后我又得到了另一个针对关键“数据”的 json 字符串,请指导我如何针对这个 json 字符串获取值,这是 json。我正在尝试使用字典来解析它,但我无法第二次解析它

 {
        AC =         (
                        {
                "ac_id" = 1;
                name = Wanted;
            },
                        {
                "ac_id" = 2;
                name = "Not Wanted";
            },
                        {
                "ac_id" = 3;
                name = Available;
            },
                        {
                "ac_id" = 4;
                name = "Not Available";
            }
        );
        Accomodation =         (
                        {
                "accomodation_id" = 1;
                name = Wanted;
            },
                        {
                "accomodation_id" = 2;
                name = Available;
            }
        );
        Accomodationfor =         (
                        {
                "accomodation_for_id" = 1;
                name = "Gents Bachelor";
            },
                        {
                "accomodation_for_id" = 2;
                name = "Ladies Bachelor";
            },
                        {
                "accomodation_for_id" = 3;
                name = Couple;
            },
                        {
                "accomodation_for_id" = 4;
                name = Family;
            },
                        {
                "accomodation_for_id" = 5;
                name = "Paying Guest";
            }
        );
        Accomodationtype =         (
                        {
                name = "Bed Space";
                "type_id" = 1;
            },
                        {
                name = "Studio Room";
                "type_id" = 2;
            },
                        {
                name = "Sharing room in flats/appartments";
                "type_id" = 3;
            },
                        {
                name = "Sharing room in House/Villa";
                "type_id" = 4;
            },
                        {
                name = "Flat/Appartment";
                "type_id" = 5;
            }
        );
        Cities =         (
                        {
                "city_id" = 1;
                "country_id" = 1;
                name = Lahore;
            },
                        {
                "city_id" = 2;
                "country_id" = 1;
                name = Islamabad;
            },
                        {
                "city_id" = 3;
                "country_id" = 1;
                name = Multan;
            },
                        {
                "city_id" = 4;
                "country_id" = 1;
                name = Karachi;
            },
                        {
                "city_id" = 5;
                "country_id" = 1;
                name = Queta;
            },
                        {
                "city_id" = 6;
                "country_id" = 2;
                name = Mumbai;
            },
                        {
                "city_id" = 7;
                "country_id" = 2;
                name = Delhi;
            },
                        {
                "city_id" = 8;
                "country_id" = 4;
                name = Dhaka;
            },
                        {
                "city_id" = 9;
                "country_id" = 5;
                name = "New York";
            },
                        {
                "city_id" = 10;
                "country_id" = 5;
                name = Washington;
            }
        );
        Cooking =         (
                        {
                "cooking_id" = 1;
                name = Wanted;
            },
                        {
                "cooking_id" = 2;
                name = "Not Wanted";
            },
                        {
                "cooking_id" = 3;
                name = Available;
            },
                        {
                "cooking_id" = 4;
                name = "Not Available";
            }
        );
        Countries =         (
                        {
                "country_id" = 1;
                name = Pakistan;
            },
                        {
                "country_id" = 2;
                name = India;
            },
                        {
                "country_id" = 4;
                name = Bangladesh;
            },
                        {
                "country_id" = 5;
                name = USA;
            }
        );
        Furnish =         (
                        {
                "furnish_id" = 1;
                name = "Fully furnished";
            },
                        {
                "furnish_id" = 2;
                name = "Semi furnished";
            },
                        {
                "furnish_id" = 3;
                name = "Not furnished";
            }
        );
        Nationality =         (
                        {
                name = Pakistani;
                "nationality_id" = 1;
            },
                        {
                name = Indian;
                "nationality_id" = 2;
            },
                        {
                name = American;
                "nationality_id" = 3;
            },
                        {
                name = Russian;
                "nationality_id" = 4;
            }
        );
        Power =         (
                        {
                name = "Govt.Authority";
                "power_id" = 1;
            },
                        {
                name = "Building Generator";
                "power_id" = 2;
            }
        );
        Religion =         (
                        {
                name = Islam;
                "religion_id" = 1;
            },
                        {
                name = Christianity;
                "religion_id" = 2;
            },
                        {
                name = Judaism;
                "religion_id" = 3;
            }
        );
    }
)
4

1 回答 1

0

试试下面这个。然后,

SBJSON *json=[[SBJSON alloc] init];
NSDictionary *dict = [json objectWithString:data error:&error];
NSDictionary *datadict=[dict objectForKey:@"data"];

NSDictionary *ac=[datadict objectForKey:@"AC"];
NSDictionary *Accomodation =[datadict objectForKey:@"Accomodation"];
NSDictionary *Accomodationfor =[datadict objectForKey:@"Accomodationfor"];
NSDictionary *Accomodationtype =[datadict objectForKey:@"Accomodationtype"];
NSDictionary *Cities =[datadict objectForKey:@"Cities"];
NSDictionary *Cooking =[datadict objectForKey:@"Cooking"];
NSDictionary *Countries =[datadict objectForKey:@"Countries"];
NSDictionary *Furnish =[datadict objectForKey:@"Furnish"];
NSDictionary *Nationality =[datadict objectForKey:@"Nationality"];
NSDictionary *Power =[datadict objectForKey:@"Power"];
NSDictionary *Religion =[datadict objectForKey:@"Religion"];

这些都是你的子词典。这些具有子数组。要访问使用数组概念,即“ObjectAtindex”。

于 2013-01-23T12:45:45.743 回答