zoukankan      html  css  js  c++  java
  • json数据的转换

    一://json数组类型字符串取值
    var jsonStr = '[{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"011","open":false,"pId":"01","name":"A部门"},{"id":"03","open":false,"pId":"0","name":"A部门"},{"id":"04","open":false,"pId":"0","name":"A部门"}, {"id":"05","open":false,"pId":"0","name":"A部门"}, {"id":"06","open":false,"pId":"0","name":"A部门"}]';
    var jsonObj =  JSON.parse(jsonStr);//转换为json对象
    for(var i=0;i<jsonObj.length;i++){
            alert(jsonObj[i].id);  //取json中的值
    }
    console.log(jsonObj)
    var jsonStr1 = JSON.stringify(jsonObj)
    console.log(jsonStr1+"jsonStr1")

    二:

    public static void main(String[] args) throws Exception {
    List list=new ArrayList<>() ;
    ArrayList<Object> alist=new ArrayList<>();
      Map<Object, List> map=new HashMap<Object, List>();
    list.add("ss");
    list.add("dd");
    alist.add("hh");
    alist.add("yy");
    map.put("a", list);
    map.put("b", alist);
    String ss=JSON.toJSONString(map);

    JSONObject jsonObject=JSON.parseObject(ss);

    String hhString=jsonObject.getString("a");

    JSONArray ssssArray=(JSONArray) JSONArray.parse(hhString);
    System.out.println(ssssArray.get(0));



    }

     三:

    Map mapsMap=new HashMap<>();
    mapsMap.put("1", 2);
    mapsMap.put("2", 3);
    Map<Object, Map> map=new HashMap<Object, Map>();

    map.put("a", mapsMap);
    map.put("b", mapsMap);
    String ss=JSON.toJSONString(map);

     System.out.println(ss);

    String hhString=jsonObject.getString("a");

    System.out.println(hhString);

    }

    
    
  • 相关阅读:
    数据预处理
    数据挖掘-聚类分析
    数据挖掘分类--判别式模型 ----支持向量机
    神经网络
    数据挖掘-贝叶斯定理
    数据挖掘之分类和预测
    关于stm32的IO口的封装
    星际炸弹——炸弹爆炸时间计算
    共阳极数码管三极管驱动
    自定义的TIME.H头文件
  • 原文地址:https://www.cnblogs.com/cws-kf/p/8630615.html
Copyright © 2011-2022 走看看