无法从NSDictionary中提取所需的信息 [英] Can't extract needed information from NSDictionary
本文介绍了无法从NSDictionary中提取所需的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我解析一个XML文件,解析后得到一个NSDictionary对象(命名为XMLDictionary).我在解析这个:
I parse a XML file, and after parsing get a NSDictionary object (XMLDictionary named). I'm parsing this:
<result><node><id>27</id><name>Name 1</name><type>0</type><price>0</price><img>/upload/iblock/1a1/1a138b2d4da6e42398beeb21acc8e84f.png</img></node><node><id>28</id><name>Name 2</name><type>0</type><price>0</price><img>/upload/iblock/b72/b724d1550f93987a73b04974b5f7390e.png</img></node></result>
之后,我正在尝试使用此方法(titleArr-NSArray):
After that i'm trying this (titleArr - NSArray):
_titleArr = [[[[_xmlDictionary objectForKey:@"result"] objectForKey:@"node"] objectForKey:@"name"] valueForKey:@"text"];
在运行时,我在上面的行中收到此错误:线程1:信号SIGABRT".我该如何解决这个问题?
In Run-time I get this error in the above line: "Thread 1: signal SIGABRT". How can i fix this problem?
推荐答案
NSError* parseError = nil;
_xmlDictionary = [XMLReader dictionaryForXMLString:myXMLString error:&parseError];
if (parseError != nil) {
NSLog(@"Error on XML parse: %@", parseError);
}
NSLog(@"The full dictionary is %@", _xmlDictionary);
NSDictionary* result = [_xmlDictionary objectForKey:@"result"];
NSLog(@"'result' = %@", result);
NSDictionary* node = [result objectForKey:@"node"];
NSLog(@"'node' = %@", node);
NSString* name = [node objectForKey:@"name"];
NSLog(@"'name' = %@", name);
至少,如果失败,该错误将被隔离到一个操作中.然后,NSLogs将在每个步骤之后为您显示这些值.
At the very least, if it fails, the error will be isolated to a single operation. And the NSLogs will show you the values after each step.
这篇关于无法从NSDictionary中提取所需的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文