De serialize html escape characters using simple xml converter in retrofit android

荒凉一梦 提交于 2019-12-11 14:39:43

问题


How can we deserialize html escape characters in inner tags of xml of a response body to be saved in POJO classes using simple xml converter in retrofit android?

<?xml version="1.0" encoding="utf-8"?>
<sample>
  <outer>
    &lt;test&gt;data<&lt;/test>&gt;
  </outer>
</sample>

回答1:


This should do it

@Root
public class Sample {
    @Element
    Outer outer;
}

public class Outer {
    @Text
    String text;

    public Test test;

    public Xml(@Text String text) {
        Serializer serializer = new Persister();
        try {
            example = serializer.read(Test.class, text);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

public class Test {

    @Element
    public String data;
}


来源:https://stackoverflow.com/questions/58980482/de-serialize-html-escape-characters-using-simple-xml-converter-in-retrofit-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!