我正在开发一个应用程序,在该应用程序中我JSON
从一个 URL 获得响应。在那个JSON
响应中,我必须先解析JSONObject
。然后,我必须解析 .xml 文件中的 XML 内容JSONObject
。JSON
这是我得到的响应示例:
{
"output": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Results>\n <Feed prov=\"dmoz\">\n <ResultSet id=\"webListings\" source=\"DMOZ\">\n <Listing description=\" - A bike shop in Brisbane. Stocks mountain bikes, road bikes, and BMX bikes.\n \" rank=\"1\" siteHost=\"http://www.lifecycle.net.au/\" title=\"Lifecycle Bike Shop\">\n <ClickUrl type=\"body\">http://www.lifecycle.net.au/</ClickUrl>\n </Listing>\n <Listing description=\" - Videos and pictures taken of both sport bikes and dirt bikes.\n \" rank=\"2\" siteHost=\"http://roadanddirt.com/\" title=\"Road and Dirt\">\n <ClickUrl type=\"body\">http://roadanddirt.com/</ClickUrl>\n </Listing>\n</Results>"
}
XML
这是我用于解析 API 并进入的Java 代码String
:
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet("API here");
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet, rHandler);
JSONObject json = new JSONObject(data);
// get xml string form jsonObject
String str_xml = json.getString("output");
我已经解析了JSONObject
a 中String
的整个 XML,现在我必须解析整个 XML 并修复列表视图中的那些,明智的分类。请帮助我解析XML
并将它们修复到列表视图中。帮助将不胜感激。