1

我正在使用 NSURLCONnection 解析俄罗斯 RSS。我面临的问题是当我解析

我现在得到俄语字符串,我正在尝试将其转换为字典但无法转换,因为它总是返回 nil。

这是我的代码

NSString*     responseStr = [[NSString alloc] initWithData:responseData        encoding:NSUTF16StringEncoding];
NSError*      error;
NSDictionary* dicfromStr  = [XMLReader dictionaryForXMLString:responseStr error:&error]; 

这是我得到的示例 xml

<rss version="2.0">
  <channel>
    <title>TEST DATA</title>
    <language>ru</language>
    <description>TEST DATA</description>
    <link>http://russianwave.com.cy/news/rss/</link>
    <pubDate>Wed, 12 Dec 2012 10:44:06 +0600</pubDate>
    <generator>KohanaPHP</generator>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/187</link>
      <guid>http://russianwave.com.cy/news/show/187</guid>
      <description>TEST DATA</description>
      <pubDate>Tue, 11 Dec 2012 18:45:13 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/186</link>
      <guid>http://russianwave.com.cy/news/show/186</guid>
      <description>manish jain</description>
      <pubDate>Tue, 11 Dec 2012 17:44:10 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/185</link>
      <guid>http://russianwave.com.cy/news/show/185</guid>
      <description>manish jain</description>
      <pubDate>Tue, 11 Dec 2012 15:39:22 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/184</link>
      <guid>http://russianwave.com.cy/news/show/184</guid>
      <description>manish jain</description>
      <pubDate>Mon, 10 Dec 2012 19:36:05 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/183</link>
      <guid>http://russianwave.com.cy/news/show/183</guid>
      <description>manish jain</description>
      <pubDate>Mon, 10 Dec 2012 19:26:48 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/182</link>
      <guid>http://russianwave.com.cy/news/show/182</guid>
      <description>manish jain</description>
      <pubDate>Mon, 10 Dec 2012 16:00:43 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/181</link>
      <guid>http://russianwave.com.cy/news/show/181</guid>
      <description>manish jain</description>
      <pubDate>Fri, 07 Dec 2012 20:00:01 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/180</link>
      <guid>http://russianwave.com.cy/news/show/180</guid>
      <description>manish jain</description>
      <pubDate>Fri, 07 Dec 2012 19:54:40 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/179</link>
      <guid>http://russianwave.com.cy/news/show/179</guid>
      <description>manish jain</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/178</link>
      <guid>http://russianwave.com.cy/news/show/178</guid>
      <description>manish jain</description>
      <pubDate>Thu, 06 Dec 2012 21:20:57 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/177</link>
      <guid>http://russianwave.com.cy/news/show/177</guid>
      <description>manish jain</description>
      <pubDate>Thu, 06 Dec 2012 21:16:06 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/176</link>
      <guid>http://russianwave.com.cy/news/show/176</guid>
      <description>manish jain</description>
      <pubDate>Thu, 06 Dec 2012 15:43:40 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/175</link>
      <guid>http://russianwave.com.cy/news/show/175</guid>
      <description>manish jain</description>
      <pubDate>Wed, 05 Dec 2012 19:30:46 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/174</link>
      <guid>http://russianwave.com.cy/news/show/174</guid>
      <description>manish jain</description>
      <pubDate>Wed, 05 Dec 2012 19:26:38 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/173</link>
      <guid>http://russianwave.com.cy/news/show/173</guid>
      <description>manish jain</description>
      <pubDate>Wed, 05 Dec 2012 15:41:08 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/171</link>
      <guid>http://russianwave.com.cy/news/show/171</guid>
      <description>manish jain</description>
      <pubDate>Tue, 04 Dec 2012 19:11:41 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/170</link>
      <guid>http://russianwave.com.cy/news/show/170</guid>
      <description>manish jain</description>
      <pubDate>Tue, 04 Dec 2012 19:05:07 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/169</link>
      <guid>http://russianwave.com.cy/news/show/169</guid>
      <description>manish jain</description>
      <pubDate>Tue, 04 Dec 2012 18:53:50 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/168</link>
      <guid>http://russianwave.com.cy/news/show/168</guid>
      <description>manish jain</description>
      <pubDate>Tue, 04 Dec 2012 18:49:23 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/167</link>
      <guid>http://russianwave.com.cy/news/show/167</guid>
      <description>manish jain</description>
      <pubDate>Mon, 03 Dec 2012 20:19:42 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/166</link>
      <guid>http://russianwave.com.cy/news/show/166</guid>
      <description>manish jain</description>
      <pubDate>Mon, 03 Dec 2012 18:56:53 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/164</link>
      <guid>http://russianwave.com.cy/news/show/164</guid>
      <description>manish jain</description>
      <pubDate>Mon, 03 Dec 2012 17:03:21 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/162</link>
      <guid>http://russianwave.com.cy/news/show/162</guid>
      <description>manish jain</description>
      <pubDate>Fri, 30 Nov 2012 16:28:05 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/161</link>
      <guid>http://russianwave.com.cy/news/show/161</guid>
      <description>manish jain</description>
      <pubDate>Fri, 30 Nov 2012 16:21:56 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/159</link>
      <guid>http://russianwave.com.cy/news/show/159</guid>
      <description>manish jain</description>
      <pubDate>Thu, 29 Nov 2012 19:11:38 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/158</link>
      <guid>http://russianwave.com.cy/news/show/158</guid>
      <description>manish jain</description>
      <pubDate>Thu, 29 Nov 2012 19:06:06 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/157</link>
      <guid>http://russianwave.com.cy/news/show/157</guid>
      <description>manish jain</description>
      <pubDate>Thu, 29 Nov 2012 18:27:57 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/155</link>
      <guid>http://russianwave.com.cy/news/show/155</guid>
      <description>manish jain</description>
      <pubDate>Wed, 28 Nov 2012 19:27:58 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/154</link>
      <guid>http://russianwave.com.cy/news/show/154</guid>
      <description>manish jain</description>
      <pubDate>Wed, 28 Nov 2012 19:24:02 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/152</link>
      <guid>http://russianwave.com.cy/news/show/152</guid>
      <description>manish jain</description>
      <pubDate>Tue, 27 Nov 2012 19:02:32 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/151</link>
      <guid>http://russianwave.com.cy/news/show/151</guid>
      <description>manish jain</description>
      <pubDate>Tue, 27 Nov 2012 18:53:11 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/150</link>
      <guid>http://russianwave.com.cy/news/show/150</guid>
      <description>manish jain</description>
      <pubDate>Tue, 27 Nov 2012 18:41:16 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/149</link>
      <guid>http://russianwave.com.cy/news/show/149</guid>
      <description>manish jain</description>
      <pubDate>Tue, 27 Nov 2012 18:26:07 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/147</link>
      <guid>http://russianwave.com.cy/news/show/147</guid>
      <description>manish jain</description>
      <pubDate>Mon, 26 Nov 2012 21:21:23 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/141</link>
      <guid>http://russianwave.com.cy/news/show/141</guid>
      <description>manish jain</description>
      <pubDate>Thu, 22 Nov 2012 20:34:33 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/140</link>
      <guid>http://russianwave.com.cy/news/show/140</guid>
      <description>manish jain</description>
      <pubDate>Thu, 22 Nov 2012 20:19:16 +0600</pubDate>
    </item>
    <item>
      <title>Michael Jackson. The legend continues.</title>
      <link>http://russianwave.com.cy/news/show/136</link>
      <guid>http://russianwave.com.cy/news/show/136</guid>
      <description>manish jain</description>
      <pubDate>Thu, 22 Nov 2012 15:33:42 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/134</link>
      <guid>http://russianwave.com.cy/news/show/134</guid>
      <description>manish jain</description>
      <pubDate>Wed, 21 Nov 2012 20:34:39 +0600</pubDate>
    </item>
    <item>
      <title>The Cyprus investors show 2013</title>
      <link>http://russianwave.com.cy/news/show/133</link>
      <guid>http://russianwave.com.cy/news/show/133</guid>
      <description>manish jain</description>
      <pubDate>Wed, 21 Nov 2012 20:31:56 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/132</link>
      <guid>http://russianwave.com.cy/news/show/132</guid>
      <description>manish jain</description>
      <pubDate>Wed, 21 Nov 2012 20:25:09 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/128</link>
      <guid>http://russianwave.com.cy/news/show/128</guid>
      <description>manish jain</description>
      <pubDate>Tue, 20 Nov 2012 19:22:08 +0600</pubDate>
    </item>
    <item>
      <title>TEST DATA</title>
      <link>http://russianwave.com.cy/news/show/100</link>
      <guid>http://russianwave.com.cy/news/show/100</guid>
      <description>manish jain</description>
      <pubDate>Thu, 08 Nov 2012 20:35:04 +0600</pubDate>
    </item>
  </channel>
</rss>
4

1 回答 1

0

假设 XML 格式正确(在您显示完整文档之前我们无法知道),您显示的部分仍然是无效 XML 的一部分。&nbsp在明确声明之前,您不能在 XML 文档中使用实体:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml:spaces [ <!ENTITY nbsp "&#160;"> ]>
<rss version="2.0">
    <channel>
        <title>\u041d\u043e\u0432\u043e\u0441\u0442\u0438</title>
        <language>ru</language> .....

详情请查看参考资料

于 2012-12-12T09:11:08.527 回答