Java后端Controller层解析Json数组转对象

Java后端Controller层解析Json数组转对象

var result={"total ": total ,“startTime”:startTime,“endTime”:endTime,“data”:data};
data是一个数组;
[{userId=17116, username=sup010001, userType=1},
{userId=17116, username=sup010001, userType=1, }]

代码演示

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

	JSONObject jsStr = JSONObject.parseObject(result);
			String total = jsStr.getString("total");
		    JSONArray jsonArray = (JSONArray) jsStr.get("data");
			List<UserNorthListVO> userList = (List<UserNorthListVO>) JSONArray.parseArray(jsonArray.toString(), UserNorthListVO.class);

解析后执行业务逻辑:

for (UserNorthListVO userNorthListVO : userList) {
				log.info("###userNorthListVO:" + userNorthListVO);
				userId = userNorthListVO.getUserId();
				log.info("###userId:" + userId);
				String username = userNorthListVO.getUsername();
				log.info("###username:" + username);
				if (recod.getSupplierAccount().equals(username) && userId != null) {
					break;
				}
			}

你可能感兴趣的:(Java后端Controller层解析Json数组转对象)