Parsing JSON object in Android Studio, Object not updating in try block -


i working on college project , trying parse timetable information api appears this:

"1474239600000" : {     "coursecode" : "case4",         "modulecodes" : [ "careersservice" ],     "moduledescription" : "careers svs. slots in year 4s",         "starttime" : 1474286400000,          "endtime" : 1474290000000,       "locations" : [ "gla.xg21", "gla.q119" ],             "type" : "seminar"        } 

i running parsing code in asynctask of android activity. here code have done this:

protected lecture doinbackground(string... urls) {     lecture lec = new lecture();  try{          bufferedreader in = new bufferedreader(         new filereader("json.txt"));           string inputline;               string content = "";      while ((inputline = in.readline()) != null) {             content = content + inputline;             system.out.println(inputline);             //log.d("input:",inputline);         }       jsonobject obj = new jsonobject(content);     string coursecode = obj.getstring("coursecode");      string moduledescription = obj.getstring("moduledescription");          string type = obj.getstring("type");     lec = new lecture(coursecode,"test",moduledescription,type);         }catch(exception e){             log.e("json parser:","catch error");             e.printstacktrace();         }         return lec;     }     

when return lecture object lec, not showing values assigned in try block default values set lecture.

i appreciate possible,

thanks, ryan.

your json malformed. change json following structure code should work:

{     "coursecode" : "case4",         "modulecodes" : [ "careersservice" ],     "moduledescription" : "careers svs. slots in year 4s",         "starttime" : 1474286400000,          "endtime" : 1474290000000,       "locations" : [ "gla.xg21", "gla.q119" ],             "type" : "seminar"    } 

a json key can't root element of json document, in case "1474239600000". because of receiving exception because jsonobject can't created.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -