Loop through JSON Array into android sql lite database by tag? -


i have function gets json. here format question of json.

    [{"chapternum":"1","courseid":"37","chapterid":"30"},     {"chapternum":"2","courseid":"37","chapterid":"31"},         {"chapternum":"3","courseid":"37","chapterid":"32"}] 

i want take "chapternum" value , store android sqlite database.

i confused how loop through , put db...

for previous db entry this.

public long addstudentinfotodb(string stuid,string stufname, string stulname) {     contentvalues student_info = new contentvalues();      student_info.put(stu_id, stuid);     student_info.put(stu_fname, stufname);     student_info.put(stu_lname, stulname);     return mdb.insert("student", null, student_info);  } 

so thinking like

public long addchapterstodb() {     contentvalues chapter_info = new contentvalues();        ///loop through jarray             ///read array contentvalues          return mdb.insert("chapter", null, chapter_info); } 

any ideas?

public long addchapterstodb() {     jsonarray jsonarray = new jsonarray(response);     for(int i=0; i<jsonarray.length(); i++){        jsonobject jsondata = jsonarray.getjsonobject(i);        string chapternum =  jsondata.getstring("chapternum");        string courseid = jsondata.getstring("courseid");        string chapterid = jsondata.getstring("chapterid");         contentvalues chapter_info = new contentvalues();        chapter_info.put(chapternum, chapternum);        chapter_info.put(courseid, courseid);        chapter_info.put(chapterid, chapterid);         mdb.insert("chapter", null, chapter_info);     } } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -