zoukankan      html  css  js  c++  java
  • json字符串转成 json对象 json对象转换成java对象

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


    依赖包

    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.54</version>
    </dependency>





    String result = ""; //下面是把拿到的json字符串转成 json对象 JSONObject jsStr = JSONObject.parseObject(requestBody); //将字符串{“id”:1} //int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值 /** * json对象转换成java对象 */ InvestorApplyModel stud = (InvestorApplyModel) JSONObject.toJavaObject(jsStr,InvestorApplyModel.class); }




    /** 
    * json字符串转转换成json数组 
    */
     
    String schedules = "";
    JSONArray schedulesArray= JSONArray.parseArray(schedules);
    JSONObject jostr = null;

    for (int sched = 0; sched <schedulesArray.size() ; sched++) {

    //获取json对象
    jostr = schedulesArray.getJSONObject(0);
    //System.out.println("jostr---" + jostr);

    /** 
    * json对象转换成java对象 
    */

    BerthStop berthStopDo = (BerthStop) JSONObject.toJavaObject(jostr, BerthStop.class);







     JSONObject cs = ssel.getCsSchedule();
        JSONArray ss = cs.getJSONArray("hh");
        if (ss == null) {
          return;
        }
        int Len = ss.size();
        List<JSONObject> aa = new ArrayList<>();
        for (int i = 0; i < Len - 1; i++) {
          JSONObject current = (JSONObject) ss.get(i);
          JSONObject nextStop = (JSONObject) ss.get(i + 1);
          if (hasIdleTime(current, nextStop)) {
            logger.info("yyyyye " + ssel.getId());
            JSONObject bb = new JSONObject();
            bb.put("from", pick(current, cc));
            bb.put("to", pick(nextStop, cc));
            aa.add(bb);
          }
        }
    
    
    
     
  • 相关阅读:
    PHP调试的时候出现了警告:
    快报滚动
    js foreach、map函数
    箭头函数和普通函数的区别
    flex布局
    react+propTypes
    手机尺寸
    less的使用
    发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的
    div+css 组织结构
  • 原文地址:https://www.cnblogs.com/JonaLin/p/11049865.html
Copyright © 2011-2022 走看看