iOS:如何从一个字典内的数组内的对象中获取值?

Posted

技术标签:

【中文标题】iOS:如何从一个字典内的数组内的对象中获取值?【英文标题】:iOS: How can I get value from object which is inside an array, which is inside one dictionary? 【发布时间】:2017-11-29 15:05:37 【问题描述】:

我得到这样的 JSON:


    response =  
        message = (
            "Permission denied, you do not have permission to access the requested page."
        );
    ;

我要打印:

“权限被拒绝,您无权访问请求的页面。”

如何获得价值?

【问题讨论】:

读大括号/括号是字典,键下标()是数组,索引下标。该字符串是根字典中键 response 的字典中键 message 的数组中的第一项。 尝试解析 JSON 作为第一步 - 你会弄清楚其余的。 这会对你有所帮助 - ***.com/questions/5547311/… 【参考方案1】:

在目标 C 中

 NSArray *arrRes = [[jsonRes objectForKey:@"response"] objectForkey:@"message"];
 NSLog(@"The output result is - %@",arrRes);

如果你想从数组中打印字符串,请执行以下操作

for(int i=0;i<arrRes.count;i++)
        NSString *strRes = arrRes[i];
        NSLog(@"The strRes is - %@",strRes);

【讨论】:

以上是关于iOS:如何从一个字典内的数组内的对象中获取值?的主要内容,如果未能解决你的问题,请参考以下文章