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:]: unrecognized selector sent to instance 0xde7ecf0”。

我将dict1类文件夹作为nsmutable数组。任何人都可以帮助我实现这一目标吗?

4

1 回答 1

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

读取上面的 json 响应,它是一个字典,其中第一个对象是字符串,第二个是字典数组(它只有一个对象)。

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 回答