gson使用 json

		Gson gson=new Gson();
		String jj="{\"connect\":[{\"name\":\"11111_xxx_22222\",\"source\":\"11111_o_1\",\"target\":\"22222_i_0\"},{\"name\":\"11111_xxbx_22222\",\"source\":\"11111_o_0\",\"target\":\"22222_i_1\"}],\"nodes\":[{\"id\":\"11111111111111111111\",\"i\":1,\"o\":2,\"x\":100,\"y\":100,\"text\":\"    SQL转换器1----\",\"compid\":\"89789451897489456189465413153\",\"nodeid\":\"0060011c3545419c80c2e2b32a5b25da\",\"comptype\":\"SQLconverter\",\"compname\":\"SQL转换器\",\"pic\":\"gl.png\",\"title\":\"节点名称:    SQL转换器1----\n算法名称:SQL转换器\",\"state\":\"\",\"params\":{\"x_cols\":[\"LIMIT_BAL\",\"SEX\",\"EDUCATION\",\"MARRIAGE\",\"AGE\",\"PAY_0\",\"PAY_2\",\"PAY_3\",\"PAY_4\",\"PAY_5\",\"PAY_6\",\"BILL_AMT1\",\"BILL_AMT2\",\"BILL_AMT3\",\"BILL_AMT4\",\"BILL_AMT5\",\"BILL_AMT6\",\"PAY_AMT1\",\"PAY_AMT2\",\"PAY_AMT3\",\"PAY_AMT4\",\"PAY_AMT5\",\"PAY_AMT6\"],\"y_col\":\"next_month\",\"param\":\"{\\\"fitIntercept\\\":\\\"true\\\",\\\"tol\\\":\\\"1.000001\\\",\\\"regParam\\\":\\\"0.1\\\",\\\"maxIter\\\":\\\"1004\\\",\\\"elasticNetParam\\\":\\\"0.4\\\"}\"}},{\"nodeid\":\"22222\",\"i\":2,\"o\":1,\"x\":500,\"y\":600},{\"nodeid\":\"33333\",\"i\":1,\"o\":1,\"x\":500,\"y\":170}],\"scale\":1,\"translateX\":0,\"translateY\":0}";
		Root root = gson.fromJson(jj, Root.class); 
		System.out.println(root.getNodes().get(0).getText());
		String param=root.getNodes().get(0).getParams().getParam();
		System.out.println(param);
		List<String> x_cols=root.getNodes().get(0).getParams().getX_cols();
		for (int i = 0; i < x_cols.size(); i++) {
			//System.out.println(i+":::"+x_cols.get(i));
		}
		
		   Type type = new TypeToken<Map<String, String>>() {}.getType();  
		    Map<String, String> map = gson.fromJson(param, type);  
		  
		    String showString = "";  
		    for (String keyString : map.keySet()) {  
		        showString += keyString + ":" + map.get(keyString) + "\n-----\n";  
		    }  
		    System.out.println(showString);

创建对应实体类

可以自动生成:

https://www.sojson.com/json2entity.html


转map接收二级参数{"fitIntercept":"true","tol":"1.000001","regParam":"0.1","maxIter":"1004","elasticNetParam":"0.4"}

原json文件

{
  "connect": [
    {
      "name": "11111_xxx_22222",
      "source": "11111_o_1",
      "target": "22222_i_0"
    },
    {
      "name": "11111_xxbx_22222",
      "source": "11111_o_0",
      "target": "22222_i_1"
    }
  ],
  "nodes": [
    {
      "id": "11111111111111111111",
      "i": 1,
      "o": 2,
      "x": 100,
      "y": 100,
      "text": "    SQL转换器1----",
      "compid": "89789451897489456189465413153",
      "nodeid": "0060011c3545419c80c2e2b32a5b25da",
      "comptype": "SQLconverter",
      "compname": "SQL转换器",
      "pic": "gl.png",
      "title": "节点名称:    SQL转换器1----\n算法名称:SQL转换器",
      "state": "",
      "params": {
        "x_cols": [
          "LIMIT_BAL",
          "SEX",
          "EDUCATION",
          "MARRIAGE",
          "AGE",
          "PAY_0",
          "PAY_2",
          "PAY_3",
          "PAY_4",
          "PAY_5",
          "PAY_6",
          "BILL_AMT1",
          "BILL_AMT2",
          "BILL_AMT3",
          "BILL_AMT4",
          "BILL_AMT5",
          "BILL_AMT6",
          "PAY_AMT1",
          "PAY_AMT2",
          "PAY_AMT3",
          "PAY_AMT4",
          "PAY_AMT5",
          "PAY_AMT6"
        ],
        "y_col": "next_month",
        "param": "{\"fitIntercept\":\"true\",\"tol\":\"1.000001\",\"regParam\":\"0.1\",\"maxIter\":\"1004\",\"elasticNetParam\":\"0.4\"}"
      }
    },
    {
      "nodeid": "22222",
      "i": 2,
      "o": 1,
      "x": 500,
      "y": 600
    },
    {
      "nodeid": "33333",
      "i": 1,
      "o": 1,
      "x": 500,
      "y": 170
    }
  ],
  "scale": 1,
  "translateX": 0,
  "translateY": 0
}
参考地址 https://blog.csdn.net/axuanqq/article/details/51441590
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值