0

私は次のようなjson応答をしているアプリケーションを持っています:

{
    "status":"ok",
    "dfs":[{"type":"i",
    "title":"image",
    "image_path":"https:\/\/s3.dhgdfhgfhgdhgfh\/ad_226.png"}]
}

そして私はこのように解析しています:

NSDictionary *dict=[[request responseString] JSONValue];                
NSLog(@"dict %@ ",[request responseString]);

if([[dict objectForKey:@"status"] isEqualToString:@"ok"])
{                   
    NSMutableDictionary *dict1=[dict objectForKey:@"dfs"]; 

    NSLog(@"%@",[dict1 classForCoder]);
    NSLog(@"%@dict1",dict1);
    titlelbl.text=[dict1 objectForKey:@"title"];

    if ([[dict1 objectForKey:@"type"] isEqualToString:@"i"])
    {
        ad.hidden=NO;

        NSString *imageurl=[dict1 objectForKey:@"image_path"];

        NSLog(@"%@",imageurl);
    } 

しかし、私はこのエラーが発生します:

*** キャッチされない例外 'NSInvalidArgumentException' によりアプリを終了します。理由: '-[__NSArrayM objectForKey:]: 認識されないセレクターがインスタンス 0xde7ecf0 に送信されました' .

dict1クラスフォルダーをnsmutable配列として取得しました。これを達成する方法について誰かが私を助けることができますか?

4

1 に答える 1

2
{
"status":"ok",
"dfs":
[
{
"type":"i",
"title":"image ",
"image_path":"https:\/\/s3.dhgdfhgfhgdhgfh\/ad_226.png"
}
]
}

上記のようにjson応答を読み取ります。これは辞書です。最初のオブジェクトは文字列で、2番目は辞書の配列です(オブジェクトは1つだけです)。

NSDictionary *dict = [[request responseString] JSONValue];

if([[dict objectForKey:@"status"] isEqualToString:@"ok"])
{
     NSArray* arr = [dict objectForKey:@"dfs"];
     NSDictionary* dict1 = [arr objectAtIndex:0];
enter code here
enter code here
enter code here
enter code here

// get the data from dict1 with the key value pairs, and set labels and images
}
于 2012-09-19T05:52:31.097 に答える