How to save server response which is in xml format into String variable in android? -
this question has answer here:
i have app in have send string request server , server sending me response in xml format.how can read response ans save in string variable , convert json.
server reponding reponse like:-
<response> <st-code>0</st-code> <st-desc>transaction successful</st-desc> <st-no>xxxxxx</st-no> <st-tno>111111</st-tno> <st-optno>xxxxxxxxx</st-optno>
- download following library java-json
- add library
/libs
of project - now import required libraries
import org.json.jsonexception;
import org.json.jsonobject;
import org.json.xml;
now use following code convert xml string json
samplexml = "";//xml string convert json jsonobject jsonobj = null; try { jsonobj = xml.tojsonobject(samplexml); } catch (jsonexception e) { log.e("json exception", e.getmessage()); e.printstacktrace(); } log.d("xml", samplexml); log.d("json", jsonobj.tostring());
Comments
Post a Comment