1

Google API を使用して、JSON フレームワーク (Stig B - Google コード) を使用して目的の C 型に変換した JSON を返します。

私は今、次のような構造を持っています:

responseData
    results
        [0]
            title = "Stack Overflow"
    cursor

resultsネストされた配列にアクセスして値を取得するにはどうすればよいtitleですか (私が推測している辞書)?

私はこれを試しましたが、成功しませんでした:

    for (NSString *key in [jsonObjects objectForKey:@"responseData"]) {
        NSLog(@"%@",key);
        for (NSString *element in [key valueForKey:@"results"]) {
            NSLog(@"%@",element);   
        }
    }

外側のループは配列の名前を出力するのでうまくいきますが、内側のループではresultsエラーが発生します。cursornot key value coding compliant

ありがとう

4

1 に答える 1

1

を使用NSLog([jsonObjects description])して、辞書の内容と構造を確認できます。
「結果」配列とその内容を参照するには、次の (または同様の) コードを使用できます。

NSDictionary* responseDict = [jsonObjects objectForKey:@"responseData"]; // Get your dictionary
NSArray* resultsArray = [responseDict objectForKey:@"results"]; 
for (NSDictionary* internalDict in resultsArray)
    for (NSString *key in [internalDict allKeys])
       NSLog([NSString stringWithFormat:@"%@ - %@", key, [internalDict objectForKey:key];
于 2010-01-12T12:51:37.570 に答える