我开发了android应用程序。在retrofit2.3.0的帮助下,应用程序从服务器xml加载并尝试处理它,但由于某种原因发生错误
Caused by: org.xmlpull.v1.XmlPullParserException: Unexpected token
(position:TEXT {"code":0,"messa...@1:63340 in
okhttp3.ResponseBody$BomAwareReader@534d7670)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:426)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
at org.simpleframework.xml.stream.PullReader.read(PullReader.java:105)
at org.simpleframework.xml.stream.PullReader.next(PullReader.java:89)
at org.simpleframework.xml.stream.NodeReader.readElement(NodeReader.java:111)
at org.simpleframework.xml.stream.NodeReader.readRoot(NodeReader.java:85)
at org.simpleframework.xml.stream.NodeBuilder.read(NodeBuilder.java:84)
at org.simpleframework.xml.stream.NodeBuilder.read(NodeBuilder.java:71)
at org.simpleframework.xml.core.Persister.read(Persister.java:562)
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:36)
... 9 more
服务器中的这个xml
<response>
<code>0</code>
<message>
<item>
<point_id>6320</point_id>
<shop_id>4215</shop_id>
<point_address>
Russia, Moscow.
</point_address>
</item>
</message>
</response>
请帮帮我。
答案 0 :(得分:3)
解析XML时遇到了类似的错误:
org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT @1:2 in java.io.StringReader@b7f960d)
正如我发现的那样,这是编码问题。文件使用UTF-8-BOM编码。 将文件首先转换为UTF-8然后解析后,问题就消失了。