0

json.frameworkを使用してjsonメッセージを読み込もうとしています。メッセージは、会議の詳細のネストされたコレクションです。私の望みは、すべての会議の考えを繰り返し、メッセージから読み取った詳細を使用してローカルの会議オブジェクトを作成することです。jsonの結果に含まれている15の会議のリストを取得するように見えますが、結果から個々の値を取得することはできません。

これが私のサンプルコードです。このテストにサーバーを関与させる必要がないように、jsonメッセージにファイルを使用しています。jsonメッセージはここからダウンロードできます。

-(void)TestParse:(NSString *)response
{
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"conference_calls" ofType:@"json"];
    NSString *fileContent =[[NSString alloc]initWithContentsOfFile:filePath];

    parser = [SBJsonParser new];
    NSArray *results = [parser objectWithString:fileContent];

    NSLog(@"Number of itmems in the results: --> %i", [results count]);

    for(NSDictionary *conf in results){

        //Load local objects with the values of the Conf info.

        NSLog(@"This the description %@ ",[c valueForKey:"phone_number"]);

        NSLog(@"Number of Items in Dic: %i",[conf count]);

        NSLog(@"File contents: %@",[conf description]);
    }
4

1 に答える 1

1

jsonの構造は、辞書の配列です。ただし、各ディクショナリには「conference_call」と呼ばれるキーが1つだけあり、そのキーの値は、その呼び出しのすべての詳細を含む別のディクショナリになります。

したがって、このようなものが機能するはずです:

for (NSDictionary* call in results) {

    // get the actual data for this call
    NSDictionary *callDetails = [call objectForKey:@"conference_call"];

    NSLog (@"Location is %@", [callDetails objectForKey:@"location"]);
}

お役に立てば幸いです。

于 2011-05-22T03:40:55.187 に答える