0

私はObjectivecに不慣れです。この配列の結果から取り出したいオブジェクトがいくつかあり、JSONからのものであり、助けが必要です。この配列からオブジェクトを取得するにはどうすればよいですか?機能を取得してから、属性やルート名などを取得するにはどうすればよいですか。

NSArray *directions=[jsonResult objectForKey:@"directions"];

    int i;
    NSArray *dict;
    int count = [directions count];
    for (i = 0; i < count; i++)
    {            
        NSLog (@"directions = %@", [directions objectAtIndex: i]);          
    }

取得したいオブジェクト

directions = {
features =     (
            {
        attributes =             {
            ETA = 1341190800000;
            length = 0;
            maneuverType = esriDMTDepart;
            text = "Start at 18304.680000,36152.730000";
            time = 0;
        };
        compressedGeometry = "+1+hrt+139j+0+0";
    },
            {
        attributes =             {
            ETA = 1341190800000;
            length = "1.43124650292492";
            maneuverType = esriDMTStraight;
            text = "Go southeast on PAN ISLAND EXPRESSWAY";
            time = "1.22675858855561";
        };
        compressedGeometry = "+1+hrt+139j+i9-a6+kp-bl";
    }
routeId = 1;
routeName = "18304.680000,36152.730000 - 29663.160389,40202.513760";
summary =     {
    envelope =         {
        spatialReference =             {
            wkid = 3414;
        };
        xmax = "29663.160018156";
        xmin = "18301.4360762186";
        ymax = "40229.9300290999";
        ymin = "35091.9900291003";
    };
    totalDriveTime = "24.8214824061658";
    totalLength = "17.2089251018779";
    totalTime = "24.8";
};

どうすればいいですか?

4

2 に答える 2

2

[directions objectAtIndex: i]を返しますNSDictionary。オブジェクトを取得する場合は、次の手順を実行します。

NSDictionary *dic = [directions objectAtIndex: i];
[dic valueForKey:@"routeName"] //route name
[dic valueForKey:@"routeId"] //routeId
[dic valueForKey:@"features"] //returns an nsdictionery too
[[dic valueForKey:@"features"] valueForKey:@"text"] //returns an nsdictionery too

等々

于 2012-07-02T12:28:12.077 に答える
1

方向内の各オブジェクトはでありNSDictionary、その中の各オブジェクトは辞書でもあります。したがって、次のようなものが必要になります。

NSDictionary *directions=[jsonResult objectForKey:@"directions"];
NSDictionary *features = [directions objectForKey:@"features"];

...など、すべての値を取得するまで続きます。

于 2012-07-02T12:29:15.010 に答える