由于特殊字符,无法显示从Web服务检索的数据

时间:2013-08-01 04:47:46

标签: java android special-characters spannablestring

我正在尝试从网址显示一个字段,但该字段仅显示特殊字符所在的点。例如,数据为:

什么是社交良好峰会?< / strong>< p> < p>全球社会公益峰会旨在将社会企业和慈善机构与科技和社交媒体公司联系起来,探讨如何应对世界上一些最大的困难。

但是显示时,它只显示:

什么是社交良好峰会?

我尝试使用SpannableStringBuilder但它仍然无效。这是示例代码:

public class AndroidXMLParsingActivity extends ListActivity {

    static final String URL = "http://api.eventful.com/rest/events/search?app_key=42t54cX7RbrDFczc&location=singapore";
    // XML node keys
    static final String KEY_EVENT = "event"; // parent node
    static final String KEY_TITLE = "title";
    static final String KEY_URL = "url";
    static final String KEY_DESC = "description";
    static final String KEY_START_TIME = "start_time";
    static final String KEY_STOP_TIME = "stop_time";
    static final String KEY_VENUE_NAME = "venue_name";
    static final String KEY_COUNTRY_NAME = "country_name";

    String regex = "</{0,1}.+?>";
    String replacement = "";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_EVENT);
        // looping through all item nodes <item>
        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
            // adding each child node to HashMap key => value
            map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
            map.put(KEY_URL, parser.getValue(e, KEY_URL));
            map.put(KEY_DESC, "Description: " + parser.getValue(e, KEY_DESC));
            map.put(KEY_START_TIME, parser.getValue(e, KEY_START_TIME));
            map.put(KEY_STOP_TIME, parser.getValue(e, KEY_STOP_TIME));
            map.put(KEY_VENUE_NAME, parser.getValue(e, KEY_VENUE_NAME));
            map.put(KEY_COUNTRY_NAME, parser.getValue(e, KEY_COUNTRY_NAME));
            // adding HashList to ArrayList

            menuItems.add(map);


        }



        // Adding menuItems to ListView
        ListAdapter adapter = new SimpleAdapter(this, menuItems,
                R.layout.list_item, new String[] { KEY_TITLE,  KEY_COUNTRY_NAME,
                        KEY_VENUE_NAME, KEY_START_TIME }, new int[] {
                        R.id.title, R.id.countryName, R.id.venueName,
                        R.id.startTime });

        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(KEY_DESC);

        TextView contentView = (TextView) findViewById(R.id.description);
        contentView.setText(stringBuilder);

1 个答案:

答案 0 :(得分:0)

尝试使用HTML.fromHTML(String source)方法:

public static Spanned fromHtml(String source)

提供上面提到的字符串..