如何从 NSDictionary 中获取属性?
我有一个 Web 服务,它以 JSON 格式将数据返回到我的客户端应用程序。我正在使用 TouchJson 将此数据反序列化为 NSDictionary。伟大的。字典包含一个键“结果”,结果包含一个 NSArray 对象。
这些对象在打印到日志时看起来像这样,即
NSLog(@"Results Contents: %@",[resultsArray objectAtIndex:0 ]);
输出:
Results Contents: {
creationdate = "2011-06-29 22:03:24";
id = 1;
notes = "This is a test item";
title = "Test Item";
"users_id" = 1;
}
我无法确定该对象是什么类型。如何从该对象获取属性和值?
谢谢!
I have a webservice that returns data to my client application in JSON. I am using TouchJson to then deserialize this data into a NSDictionary. Great. The dictionary contains a key, "results" and results contains an NSArray of objects.
These objects look like this when printed to log i.e
NSLog(@"Results Contents: %@",[resultsArray objectAtIndex:0 ]);
Outputs:
Results Contents: {
creationdate = "2011-06-29 22:03:24";
id = 1;
notes = "This is a test item";
title = "Test Item";
"users_id" = 1;
}
I can't determine what type this object is. How do I get the properties and values from this object?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取 NSDictionary 的内容,您必须提供要检索的值的键。 IE:
To get the content of a
NSDictionary
you have to supply the key for the value that you want to retrieve. I.e:要测试对象是否是类
a
的实例,请使用以下之一:要获取对象的类名,您可以使用以下之一:
对于
NSDictionary
,您可以使用 < code>-allKeys 返回字典键的NSArray
。这还会让您知道有多少个(通过获取数组的计数
)。一旦知道类型,您就可以调用其中
keyString
是@"creationdate"
、@"notes"
等之一。但是,如果该类不是NSObject
的子类,然后使用:例如,您可能需要对等于
@"id"
的keystring
执行此操作>。To test if object is an instance of class
a
, use one of these:To get object's class name you can use one of these:
For an
NSDictionary
, you can use-allKeys
to return anNSArray
of dictionary keys. This will also let you know how many there are (by taking thecount
of the array). Once you know the type, you can callwhere
keyString
is one of@"creationdate"
,@"notes"
, etc. However, if the class is not a subclass ofNSObject
, then instead use:for example, you probably need to do this for
keystring
equal to@"id"
.