I need to parse this json string
{
\"results\": {
\"result\": [
{
\"cover\": \"http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5
First of all please look at some tutorials like:
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
http://www.vogella.com/articles/AndroidJSON/article.html
JSONObject response = new JSONObject(respString);
ArrayList<Book> bookCollection = new ArrayList<Book>();//
if(response.has("results")){
if(response.has("result")){
JSONArray resultArray = response.getJSONArray("result");
for(int iCount=0; iCount<resultArray.length; iCount++){
JSONObject item = resultArray.getJSONObject(iCount);
Book book = new Book();
if(item.has("title")){
book.title =item.getString("title");
}
bookCollection.add(book);
}
}
}
The pojo to populate
public Book{
public String cover;
public String title;
}
You can try to Parse Current Json String as:
JSONObject response = new JSONObject(respString);
JSONObject jsonobjresults = response.getJSONObject("results");
JSONArray resultArray = jsonobjresults.getJSONArray("result");
Map<Integer,ArrayList<String>>
mapoflisp = new HashMap<Integer,ArrayList<String>>();
ArrayList<String> listofitem;
for(int i=0; i<resultArray.length; i++){
JSONObject itemobj = resultArray.getJSONObject(i);
listofitem=new ArrayList<String>();
// Add items in List
listofitem.add(item.getString("cover"));
listofitem.add(item.getString("title"));
listofitem.add(item.getString("year"));
listofitem.add(item.getString("director"));
listofitem.add(item.getString("rating"));
listofitem.add(item.getString("details"));
//add list to Map
mapoflisp.put(i,listofitem);
// your code here...
}