How to parse Complex JSON data of spreadsheet in android? -


i new android, trying parse google's spreadsheet data , complex me, have fetch $t of gsx$tag , $t of gsx$datetime,

this link can json data https://spreadsheets.google.com/feeds/list/1_ar0zx6jv0ni_r1hbulbpeiuuj2mqvblohvvlqowu1i/1/public/values?alt=json

data

{   "version":"1.0", "encoding":"utf-8",        "feed":{     "xmlns":"http://www.w3.org/2005/atom",   "xmlns$opensearch":"http://a9.com/-/spec/opensearchrss/1.0/",   "xmlns$gsx":"http://schemas.google.com/spreadsheets/2006/extended",   "id":{  },    "updated":{  },   "category":[  ],   "title":{  },   "link":[  ],   "author":[  ],   "opensearch$totalresults":{  },   "opensearch$startindex":{  },   "entry":[        {           "id":{  },         "updated":{  },         "category":[  ],         "title":{  },         "content":{  },         "link":[  ],         "gsx$id":{              "$t":"1"         },         "gsx$datetime":{              "$t":"3/28/2017"         },         "gsx$tag":{              "$t":"21"         }      },   { data here },   { data here }   ]   }   } 

and below code trying

httphandler sh = new httphandler();         // making request url , getting response         string jsonstr = sh.makeservicecall(url);          log.e(tag, "response url: " + jsonstr);         if (jsonstr != null) {             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                  jsonobject mainobj = new jsonobject(jsonstr);                 log.e(tag,"json data"+mainobj);                 if (mainobj != null) {                     log.e(tag,"json before feed"+mainobj.tostring());                     jsonarray = mainobj.getjsonarray("feed");                     log.e(tag,"json after feed"+a.tostring());                     jsonobject entru= new jsonobject((map) a);                     jsonarray list = entru.getjsonarray("entry");   //                       jsonarray entryarray = list.getjsonarray("entry");                     if (list != null) {                         (int = 0; < list.length(); i++) {                             jsonobject elem = list.getjsonobject(i);                             if (elem != null) {                                 jsonarray prods = elem.getjsonarray("gsx$tag");                                 if (prods != null) {                                     (int j = 0; j < prods.length(); j++) {                                          jsonobject innerelem = prods.getjsonobject(j);                                         if (innerelem != null) {                                             string sku = innerelem.getstring("$t");                                             log.e(tag, "$t" + sku);                                             hashmap<string, string> contact = new hashmap<>();                                              contact.put("$t datetime", sku);                                              // adding contact contact list                                             contactlist.add(contact);                                         }                                     }                                 }                             }                         }                     }                 } 

help me in regards, thank in advance

jsonarray = mainobj.getjsonarray("feed"); log.e(tag,"json after feed"+a.tostring()); jsonobject entru= new jsonobject((map) a); 

replace 3 lines below one

 jsonobject entru= mainobj.getjsonobject("feed"); 

also replace line

jsonarray prods = elem.getjsonarray("gsx$tag"); 

with 1

 jsonobject prods = elem.getjsonobject("gsx$tag"); 

i think correct code.

httphandler sh = new httphandler();     // making request url , getting response     string jsonstr = sh.makeservicecall(url);      log.e(tag, "response url: " + jsonstr);     if (jsonstr != null) {         try {             jsonobject jsonobj = new jsonobject(jsonstr);              jsonobject mainobj = new jsonobject(jsonstr);             log.e(tag,"json data"+mainobj);             if (mainobj != null) {                 log.e(tag,"json before feed"+mainobj.tostring());                 jsonobject entru= mainobj.getjsonobject("feed");                 jsonarray list = entru.getjsonarray("entry");   //jsonarray entryarray = list.getjsonarray("entry");                 if (list != null) {                     (int = 0; < list.length(); i++) {                         jsonobject elem = list.getjsonobject(i);                         if (elem != null) {                             jsonobject prods = elem.getjsonobject("gsx$tag");                             if (prods != null) {                                 (int j = 0; j < prods.length(); j++) {                                           string sku = prods.getstring("$t");                                         log.e(tag, "$t" + sku);                                         hashmap<string, string> contact = new hashmap<>();                                          contact.put("$t datetime", sku);                                          // adding contact contact list                                         contactlist.add(contact);                                  }                             }                         }                     }                 }             } 

please try this. if doesn't work please feel free ask. you


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -