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

我得到这样的 JSON:

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

我要打印:

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

如何获得价值?

【问题讨论】:

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

标签: ios objective-c nsarray nsdictionary


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多