-1

私はjson文字列を解析し、キー「データ」に対して別のjson文字列を取得しました。このjson文字列に対して値を取得する方法を教えてください。これは json です。私はそれを解析するために辞書を使用しようとしていますが、2回目に解析することはできません

 {
        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 に答える