作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个从 Twitter REST API 的 json 数据构建的 NSArray。
NSArray *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog (@"Element %@", [dict objectAtIndex: 1]);
如何从数组中获取单个元素,其中一个数组索引项如下所示:
Element 1 = {
contributors = "<null>";
coordinates = "<null>";
"created_at" = "Tue Feb 07 11:15:08 +0000 2012";
entities = {
hashtags = (
);
urls = (
);
"user_mentions" = (
);
};
favorited = 0;
geo = "<null>";
id = 166842424398848000;
"id_str" = 166842424398848000;
"in_reply_to_screen_name" = "<null>";
"in_reply_to_status_id" = "<null>";
"in_reply_to_status_id_str" = "<null>";
"in_reply_to_user_id" = "<null>";
"in_reply_to_user_id_str" = "<null>";
place = "<null>";
"retweet_count" = 0;
retweeted = 0;
source = web;
text = "another day is here so ready to be off from work already...";
....
最佳答案
你可以试试,
NSString *string = [[dict objectAtIndex: 1] objectForKey:@"keyName"];
如果我没看错的话,你的数据中有一个子字典(“entities”)
NSDictionary *entitiesDict = [[dict objectAtIndex: 1] objectForKey:@"entities"];
如前所述使用 NSDictionary :)
关于objective-c - 如何从 NSArray 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9175466/
我是一名优秀的程序员,十分优秀!