Android使用自带JSONObject解析JSON数据
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
·
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 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();
}
}
![]( https://profile-avatar.csdnimg.cn/default.jpg)
![](https://devpress.csdnimg.cn/7174e1ca86c447029bb12f9ec0bd281c.png)
![](https://devpress.csdnimg.cn/096f7827187446559bd7b6030eb5db38.png)
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
适用于现代 C++ 的 JSON。
最近提交(Master分支:2 个月前 )
6be4e856
4 天前
663058e7
6 天前
更多推荐
所有评论(0)