java - gson list object attributes are null -
i trying list object json file usiong gson. returning list objects attributes null. how objects properly?
json file:
[{"periodendp":"2014-04-06t00:00:00","sitekeyp":"00035"},{"periodendp":"2014-04-06t00:00:00","sitekeyp":"00035"}]
scheduledto.java
public class scheduledto { string periodendp; string sitekeyp; }
gsonex.java
public class gsonex { public static void main(string[] args) { try { jsonreader jsonreader = new jsonreader(new filereader("f:/schedule.txt")); gson gson = new gson(); type schedulemsgdesttype = new typetoken<list<scheduledto>>(){}.gettype(); list<scheduledto> schedulelist = gson.fromjson(jsonreader, schedulemsgdesttype); for(scheduledto t :schedulelist ) { system.out.println(t.periodendp); } } catch(exception e) { e.printstacktrace(); } }
}
make periodendp
periodendp
and same sitekeyp
sitekeyp
the names should same in json , code.
Comments
Post a Comment