我正在使用https://github.com/nicklockwood/XMLDictionary类别将服务器XML响应转换为NSDictionary。它似乎只有一半的时间工作,我不确定它是否与我使用它的方式有关,或者是否存在XMLDictionary中的错误或什么。
我正在调用这样的方法: NSDictionary * convertedData = [NSDictionary dictionaryWithXMLData:data];
这是我要解析的XML数据的一个例子(这直接来自我传递的“数据”):
<?xml version="1.0" encoding="utf-8"?>
<anime>
<entry>
<id>572</id>
<title>Kaze no Tani no Nausicaa</title>
<english>Nausicaä of the Valley of the Wind</english>
<synonyms>Nausicaa of the Valley of the Wind; Warriors of the Wind</synonyms>
<episodes>1</episodes>
<score>8.47</score>
<type>Movie</type>
<status>Finished Airing</status>
<start_date>1984-03-11</start_date>
<end_date>1984-03-11</end_date>
<synopsis>A thousand years after a global war, a seaside kingdom known as the Valley Of The Wind remains one of only a few areas still populated. Led by the courageous Princess Nausicaä, the people of the Valley are engaged in a constant struggle with powerful insects called ohmu, who guard a poisonous jungle that is spreading across the Earth. Nausicaä and her brave companions, together with the people of the Valley, strive to restore the bond between humanity and the Earth. <br />
<br />
(Source: Disney)</synopsis>
<image>http://cdn.myanimelist.net/images/anime/7/42071.jpg</image>
</entry>
</anime>
这就是我得到的结果:
打印convertedData的说明:
{
"__name" = anime;
entry = {
english = {
};
id = 572;
title = "Kaze no Tani no Nausicaa";
};
}
事情是,所有搜索结果都不会发生这种情况。通过使用相同的搜索结果可以完全重复,但是某些结果根本不会这样做。我无法弄清楚那些使其在其他人没有的情况下工作的结果有什么特别之处。这是一个有效的例子。
XML输入:
<?xml version="1.0" encoding="utf-8"?>
<anime>
<entry>
<id>329</id>
<title>Planetes</title>
<english></english>
<synonyms></synonyms>
<episodes>26</episodes>
<score>8.42</score>
<type>TV</type>
<status>Finished Airing</status>
<start_date>2003-10-04</start_date>
<end_date>2004-04-17</end_date>
<synopsis>In the year 2075, mankind has reached a point where journeying between Earth, the moon and the space stations is part of daily life. However, the progression of technology in space has also resulted in the problem of the space debris, which can cause excessive and even catastrophic damage to spacecrafts and equipment. This is the story of Technora&#039;s Debris Collecting section, its EVA worker, Hachirota &quot;Hachimaki&quot; Hoshino, and the newcomer to the group, Ai Tanabe. <br />
<br />
(Source: ANN)</synopsis>
<image>http://cdn.myanimelist.net/images/anime/8/50463.jpg</image>
</entry>
<entry>
<id>10735</id>
<title>Planetes Picture Drama</title>
<english></english>
<synonyms>Planetes Audio Drama</synonyms>
<episodes>9</episodes>
<score>6.27</score>
<type>Special</type>
<status>Finished Airing</status>
<start_date>2009-09-25</start_date>
<end_date>2009-09-25</end_date>
<synopsis>Planetes picture drama.</synopsis>
<image>http://cdn.myanimelist.net/images/anime/9/29571.jpg</image>
</entry>
</anime>
NSDictionary输出:
{
"__name" = anime;
entry = (
{
"end_date" = "2004-04-17";
episodes = 26;
id = 329;
image = "http://cdn.myanimelist.net/images/anime/8/50463.jpg";
score = "8.42";
"start_date" = "2003-10-04";
status = "Finished Airing";
synopsis = "In the year 2075, mankind has reached a point where journeying between Earth, the moon and the space stations is part of daily life. However, the progression of technology in space has also resulted in the problem of the space debris, which can cause excessive and even catastrophic damage to spacecrafts and equipment. This is the story of Technora's Debris Collecting section, its EVA worker, Hachirota "Hachimaki" Hoshino, and the newcomer to the group, Ai Tanabe. <br />\n<br />\n(Source: ANN)";
title = Planetes;
type = TV;
},
{
"end_date" = "2009-09-25";
episodes = 9;
id = 10735;
image = "http://cdn.myanimelist.net/images/anime/9/29571.jpg";
score = "6.27";
"start_date" = "2009-09-25";
status = "Finished Airing";
synonyms = "Planetes Audio Drama";
synopsis = "Planetes picture drama.";
title = "Planetes Picture Drama";
type = Special;
}
);
}
有时它只会省略某些标签,例如标签。其他时候它会省略大部分内容,就像我的第一个例子。我真的很困惑。
另外,如果我传递一个大的XML文件(比如一个包含50个项目的搜索结果),它只会解析其中的一半。我怀疑是否有人想要阅读所有内容,但为了以防万一,这里是XML http://pastebin.com/aQTc8S9x,这里是NSDictionary出来http://pastebin.com/MwuexaZV