【发布时间】:2015-10-02 05:33:46
【问题描述】:
我的字典看起来像这样。
{
thread = "{
\"uuid\": \"e9290344dee38c42782\",
\"site_full\": \"www.independent.co.uk\",
\"main_image\":\"http://www.independent.co.uk/incoming/article10498560.ece/binary/original/39-tea-party-ap.jpg\"
}";
}
[newDict valueForKeyPath:@"thread.main_image"];
我正在尝试这样访问它,但它我可以获得线程之外的所有其他值,但不能获得线程中的嵌套值。感谢任何帮助。
编辑
for (int i=0;i < [responseObject count];i++) {
NSDictionary* newDict = (NSDictionary*)responseObject[i];
if ([(NSString*)[newDict valueForKey:@"title"] isEqualToString: @""] || [newDict valueForKey:@"title"]== Nil) {
NSLog(@"Image or Title Text is null");
}
else{
NewsFeed* newsData = [NewsFeed new];
newsData.newsSource = [newDict valueForKeyPath:@"thread.site"];
newsData.newsImageLink = [newDict valueForKeyPath:@"thread.main_image"];
//these three work fine
newsData.newsTitle = [newDict valueForKeyPath:@"title"];
newsData.newsText = [newDict valueForKeyPath:@"text"];
newsData.newsDate = [newDict valueForKeyPath:@"published"];
//
NSLog(@"news Source :: %@ \n and news ImageLink:: %@ \n news Title %@ \nnews Text:: %@ \n news Date:: %@ ",newsData.newsSource,newsData.newsImageLink,newsData.newsTitle,newsData.newsText,newsData.newsDate);
[NewsData addObject:newsData];
}
}
【问题讨论】:
-
请说明您尝试了哪些代码,以及它的不足之处。
-
我已经添加了代码并且响应以数组的形式出现..
标签: ios objective-c nsdictionary