废话不多说,直接上代码
测试:
String test = "{"list":[{"id":1,"qty":20,"type":"测试","time":"2022-08-02"},{"id":2,"qty":10,"type":"测试","time":"2022-08-02"},{"id":3,"qty":17,"type":"测试","time":"2022-08-02"}]}"
JSONObject obj = JSONObject.fromObject(test);
Object object = obj.get("list");
JSONArray jsonObject = JSONArray.fromObject(object);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //日期格式化
for(int i = 0;i < jsonObject.size(); i++){
JSONObject onecar = jsonObject.getJSONObject(i);
int uid = onecar.getInt("id");
int qty = onecar.getInt("qty");
String type = onecar.getString("type");
String time = onecar.getString("time");
try {
times = sdf.parse(time); //日期需要try一下不然会异常
} catch (ParseException e) {
e.printStackTrace();
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有