import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;


public void allInfoFromJson(String jsonStr){

/*{ "listMsg":"数据获取成功",
"
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 jsonObject=new JSONObject(jsonStr).getJSONObject("list");

JSONArray jsonArray=new JSONObject(jsonStr).getJSONArray("list");

for(int i=0;i<jsonArray.length();i++){

JSONObject 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 bus=new Bus(busName,busLine,firstTime,lastTime,price,cityId,districtId);
BusService busService=new BusService(context);
busService.save(bus);
}

} catch (JSONException e) {
e.printStackTrace();
}
}

更多相关文章

  1. Android(安卓)获取activity栈中activity
  2. Android获取设备信息(利用反射)
  3. 获取手机系统
  4. Android(安卓)获取内存信息
  5. android群发短信时判断短信是否发送成功
  6. Android中Environment,context获取路径
  7. Android常用代码
  8. android中获取通话记录
  9. Android文件夹大小

随机推荐

  1. 如何监听Phone的状态,第三方App如何拨打/
  2. android 自定义带进度值的圆形进度条
  3. Android BottomNavigationBar底部导航控
  4. 下拉刷新系列二:SmartRefreshLayout 使用
  5. Annotation Processor在Android下的应用
  6. Android网络编程之——Android登录系统模
  7. Android媒体扫描代码分析
  8. 什么是Anddroid ANR
  9. [置顶] 定义一个ImageVIew出现警告的去除
  10. 用SQLiteOpenHelper实现操作SQLite