前端之家收集整理的这篇文章主要介绍了
jsonArray 的遍历,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
private String json = "{\"address\":\"cc\",\"person\":\"Lily\","+
"\"body\":\"发送短信成功\",\"id\":22,\"datetime\":\"2014-02-23\"},"
+ "{\"address\":\"cc\",\"datetime\":\"2014-02-23\"}";
protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
json = "[" + json + "]";
JSONArray jsonArray = JSONArray.fromObject(json);
Object[] os = jsonArray.toArray();
System.out.println(os.length);
SmsInfo[] smsInfoList = (SmsInfo[]) JSONArray.toArray(jsonArray,SmsInfo.class);
System.out.println(smsInfoList.length);
System.out.println(smsInfoList[0].getId());
for(int i=0;i<smsInfoList.length;i++){
SmsInfo smsInfo=new SmsInfo();
smsInfo.setAddress(smsInfoList[i].getAddress());
smsInfo.setBody(smsInfoList[i].getBody());
smsInfo.setDate(smsInfoList[i].getDate());
smsInfo.setPerpon(smsInfoList[i].getPerpon());
smsInfo.setDatetime(smsInfoList[i].getDatetime());
smsInfo.setType(smsInfoList[i].getType());
getSmsInfoService().save(smsInfo);
}
}
原文链接:https://www.f2er.com/json/290151.html