Import org. JSON. jsonarray;
Import org. JSON. jsonexception;
Import org. JSON. jsonobject;
Import Android. content. context;
Public void allinfofromjson (string jsonstr ){
/*{"Listmsg": "data obtained successfully ",
"List":[
{"Busid": 1, "busline": "", "busname": "501", "cityid": 2, "districtid": 1,
"Firsttime": "8:00", "lasttime": "19:00", "price": 4, "version": 0 },
{"Busid": 2, "busline": "502", "busname": "502", "cityid": 2, "districtid": 2,
"Firsttime": "2", "lasttime": "2", "price": 2, "version": 0 },
{"Busid": 3, "busline": "AAA", "busname": "601", "cityid": 2, "districtid": 1,
"Firsttime": "AA", "lasttime": "AA", "price": 1, "version": 0}
],
"Nversion": 3}*/
Try {
// Jsonobject = new jsonobject (jsonstr). getjsonobject ("list ");
Jsonarray = new jsonobject (jsonstr). getjsonarray ("list ");
For (INT I = 0; I <jsonarray. Length (); I ++ ){
Jsonobject = (jsonobject) jsonarray. Get (I );
String busline = jsonobject. getstring ("busline ");
String busname = jsonobject. getstring ("busname ");
Integer cityid = jsonobject. getint ("cityid ");
Integer districtid = jsonobject. getint ("districtid ");
String firsttime = jsonobject. getstring ("firsttime ");
String lasttime = jsonobject. getstring ("lasttime ");
Double price = jsonobject. getdouble ("price ");
Bus = new bus (busname, busline, firsttime, lasttime, price, cityid, districtid );
Busservice = new busservice (context );
Busservice. Save (bus );
}
} Catch (jsonexception e ){
E. printstacktrace ();
}
}