zoukankan      html  css  js  c++  java
  • json串 转 list<class> 方法 List转JSONArray和JSONArray转List

     

    1.List转JSONArray


     

    List<T> list = new ArrayList<T>();
    JSONArray array= JSONArray.parseArray(JSON.toJSONString(list));


    2.JSONArray转List

    JSONArray array = new JSONArray();
    List<EventColAttr> list = JSONObject.parseArray(array.toJSONString(), EventColAttr.class);


     
    3.String转JSONArray

    String st = "[{name:Tim,age:25,sex:male},{name:Tom,age:28,sex:male},{name:Lily,age:15,sex:female}]";
    JSONArray tableData = JSONArray.parseArray(st);

    这是我写的;

      public static List<ProjectRestDTO> setMap(){
    
    
            String abc="[{"tenantId":15203,"projectId":328001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":357001015203,"price":[1990,2990]}]},{"tenantId":15203,"
                + ""projectId":355001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":398001015203,"price":[10000]}]},{"tenantId":15203,"
                + ""projectId":327001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":356002015203,"price":[10000]}]},{"tenantId":15203,"
                + ""projectId":212001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":224001015203,"price":[100,300]}]},{"tenantId":15203,"
                + ""projectId":366005015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":414003015203,"price":[1000,2000]}]},{"tenantId":15203,"
                + ""projectId":365006015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":414006015203,"price":[3000,4000]}]},{"tenantId":15203,"
                + ""projectId":365003015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":414004015203,"price":[100,200]}]},{"tenantId":15203,"
                + ""projectId":315001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":344003015203,"price":[1]},{"eventId":345001015203,"price":[1,"
                + "10000]},{"eventId":345002015203,"price":[10000,15000]}]},{"tenantId":15203,"
                + ""projectId":590001015203,"marketChannel":33521,"channelType":1,"
                + ""eventList":[{"eventId":717001015203,"price":[100,200]},{"eventId":719002015203,"
                + ""price":[100,200]},{"eventId":726002015203,"price":[100,200]}]},"
                + "{"eventList":[{"eventId":287001015203,"price":[100,200,300]}],"marketChannel":33521,"
                + ""tenantId":15203,"channelType":1,"projectId":253003015203}]";
    
           // List<ProjectRestDTO> nn=new ArrayList<>();
           //
           //ProjectRestDTO aa= assemble();
           //nn.add(aa);
           //EventPriceDTO eventPriceDTO=new EventPriceDTO();
           //eventPriceDTO.setEventId(287001015203L);
           //eventPriceDTO.setPrice(Arrays.asList(100L,200L,300L));
           //
           //ProjectRestDTO projectRestDTO=aa;
           //projectRestDTO.setProjectId(253003015203L);
           //projectRestDTO.setEventList(Arrays.asList(eventPriceDTO));
           //nn.add(projectRestDTO);
    
            //JSONArray array = new JSONArray();
            List<ProjectRestDTO> list = JSONObject.parseArray(abc, ProjectRestDTO.class);
    
            //List<ProjectRestDTO> jsonObject =new JSONArray(abc);
    
            //List<ProjectRestDTO> list = JSONArray.toArray(abc,ProjectRestDTO.class);
            //String aa1 = jsonObject.toString();
    
            //System.out.println(aa1);
    
    
            return list;
    
        }

    参考:List转JSONArray和JSONArray转List


     

  • 相关阅读:
    Cryptocurrency Security Compliance
    HOW TO ACHIEVE CRYPTOCURRENCY SECURITY STANDARD (CCSS) COMPLIANCE
    Cryptocurrency Security Guide@BitIRA
    How to Trade Cryptocurrency – The Complete Guide
    7 Things I Learned From Porting a C Crypto Library to Rust
    25 Places To Find Quantitative Trading Strategies
    JavaScript-Runoob-AJAX:服务器响应
    JavaScript-Runoob-AJAX:向服务器发送请求
    JavaScript-Runoob-AJAX:创建 XMLHttpRequest 对象
    JavaScript-Runoob-AJAX:AJAX 实例
  • 原文地址:https://www.cnblogs.com/aspirant/p/12462692.html
Copyright © 2011-2022 走看看