简体   繁体   English

获取JSON字典中的所有值,而无需按键访问

[英]Get all values in a JSON dictionary, without accessing by key

JSON Example: JSON示例:

[{ "title1":"Hey", "title2":"Hoh", "title3":"Hah", "title4":"Hoo" }]

How can I get value (hey,hoh,hah,hoo) without using valueForKey ? 如何在不使用valueForKey情况下获取价值(hey,hoh,hah,hoo)

Could anyone guide me please? 有人可以指导我吗?

--------------Edit-------------- - - - - - - - 编辑 - - - - - - -

I use JSON-Framework. 我使用JSON框架。 And Now I use NSDictionary *jsonDict = [string JSONValue]; 现在我使用NSDictionary * jsonDict = [string JSONValue];

Assuming you have your data in an NSDictionary, try allValues . 假设您的数据位于NSDictionary中,请尝试allValues

Remember however than an NSDictionary is unsorted, so the order of the values is undefined. 但是请记住,不是NSDictionary是未排序的,所以值的顺序是不确定的。

As Todd already said, NSDictionary has a method allValues - check the NSDictionary Documentation 正如Todd所说的那样,NSDictionary具有方法allValues-检查NSDictionary文档

An example of looping through the value's is 循环遍历值的示例是

for(NSString *value in [jsonDict allValues]){
NSLog(@"Found Value %@",value);
}

Again, these values will be unsorted as they are coming from a dictionary. 同样,这些值将不排序,因为它们来自字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM