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