android - How to get Json Array Content to ArrayList<String> in Java? -


i have json file in android "assets" folder. json file have more 5 arrays how store java arraylist or how directly json array forloop.

try way

 public static string assetjsonfile (string filename, context context) throws ioexception {     assetmanager manager = context.getassets();     inputstream file = manager.open(filename);     byte[] formarray = new byte[file.available()];     file.read(formarray);     file.close();      return new string(formarray);   }              public void getjson()    {      arraylist<hashmap<string, string>> formlist = new arraylist<hashmap<string, string>>();     context context = null;     hashmap<string, string> hashmap;      try {         string jsonlocation = assetjsonfile("yourjson.json", context);         string id;         string question;          jsonarray jsonarray = jsonobject.getjsonarray("arjuna");         {               (int k = 0; k < jsonarray.length(); k++)               {                 jsonobject jsonobject = jsonarray.getjsonobject(k);                id= jsonobject.getstring("id");               question= jsonobject.getstring("question");                hashmap = new hashmap<string, string>();               hashmap.put("id", id);               hashmap.put("question", question);                formlist.add(hashmap);              }         }      } catch (ioexception e) {         e.printstacktrace();     } catch (jsonexception e) {         e.printstacktrace();     }  } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -