• json数组转数组对象


    import java.io.IOException;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    
    import com.fasterxml.jackson.core.JsonParseException;
    import com.fasterxml.jackson.databind.JsonMappingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    public class Test {
    	
    	public static void main(String[] args) {
    		//对应实体bean WorkDataInfo 不贴了
    		 ObjectMapper objectMapper=new ObjectMapper();
    		 String str =  "[{"time":"2015-01-08 02:06:03","title":"zy","status":-1,"msgId":"f57b624d-7877-4974-94e3-1da77ad93fc0","msgType":1}]";
    
    		// List<WorkDataInfo> list;
    		try {
    			WorkDataInfo[]	list =  objectMapper.readValue(str, WorkDataInfo[].class);
                  //直接输出对象数组 for (WorkDataInfo workDataInfo : list) { System.out.println(workDataInfo.getTitle()); } } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

      

  • 相关阅读:
    Flask入门
    pippo主机管理
    K8S_v1.20+二进制安装(一)
    飞舞吧,少年
    paramiko封装
    Hippo登录展示功能
    mysql回档操作
    OpenSSH升级
    oracle存储过程 关于update的动态SQL工作心得
    关于博客的回忆
  • 原文地址:https://www.cnblogs.com/huxdiy/p/4211499.html
Copyright © 2020-2023  润新知