Here to introduce the JSON file in the Read Assets folder into the list collection
It's very simple to see the code.
Public StaticList<state>getstates (Context context) {InputStream is=NULL; Bytearrayoutputstream Bos=NULL; Try{ is= Context.getassets (). Open ("Area.json"); Bos=NewBytearrayoutputstream (); byte[] bytes =New byte[4 * 1024]; intLen = 0; while(len = is.read (bytes))! =-1) {bos.write (bytes,0, Len); } FinalString JSON =NewString (Bos.tobytearray ()); FinalAreas areas = Json.parseobject (JSON, areas.class); Finallist<state> states =areas.getstates (); returnstates; } Catch(Exception e) {e.printstacktrace (); } finally { Try { if(Is! =NULL) Is.close (); if(Bos! =NULL) Bos.close (); } Catch(IOException e) {log.e (TAG,"GetStates", E); } } return NULL; }
It's OK to write the entity class with JSON.
Android read JSON file in assets folder