I’m developing an application in which I’m getting JSON response from a URL. In that JSONresponse I have to parse JSONObject first. And, then I have to parse XML content in the JSONObject. Here is the sample of JSON response that I’m getting:
{
"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>"
}
Here is my Java code for parsing the API and getting XML in a 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");
I have parsed the JSONObject and now getting XML as a whole in a String, now I have to parse the whole XML and fix those in the listview, category wise. Please help me in parsing the XML and fixing those into listview. Help will be appreciated.
get xml string from current json as :