Parsing Json String Obtained Frm Server In Android
I had gone through a link on parsing Json data on Android, but didnt understand pretty much. I am getting the following JSON String from my server. I need to parse it and present
Solution 1:
Make Arraylist of All Fields and Write below function to parse above json, it will solve your problem.
ArrayList<String> year, title, details, director, rating, cover;
// For Parse Login Response From ServerpublicvoidmParseResponse() throws UnknownHostException {
year=newArrayList<String>();
title=newArrayList<String>();
details=newArrayList<String>();
director=newArrayList<String>();
rating=newArrayList<String>();
cover=newArrayList<String>();
try {
JSONObject jObject = newJSONObject(EntityUtils.toString(entity));
JSONObject jsonobjresults = jObject.getJSONObject("results");
JSONArray jsonarrayresult = jsonobjresults.getJSONArray("result");
for(int i=0;i<jsonarrayresult.length(); i++){
JSONObject mJsonObj = jsonarrayresult.getJSONObject(i);
year.add(mJsonObj.getString("year"));
title.add(mJsonObj.getString("title"));
details.add(mJsonObj.getString("details"));
director.add(mJsonObj.getString("director"));
rating.add(mJsonObj.getString("rating"));
cover.add(mJsonObj.getString("cover"));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Solution 2:
read this tutorial http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html.
You can use gson library of Google to parse json. you need to create java classes to store json values passs that class ref to gson libary. It has simple methods.
chec this doc
Post a Comment for "Parsing Json String Obtained Frm Server In Android"