【发布时间】:2020-01-21 19:04:52
【问题描述】:
在处理表示二维矩阵的有效 JSON 时:
[ { "a":1, "b":2 }, { "b":3, "c":4 }, { "c":6, "a":5 } ]
使用 Java 1.8 和 json-simple 库:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
是否能够使用以下方法获得单独的行?:
JSONParser parser = new JSONParser();
Object obj = parser.parse(args[0]);
JSONArray array = (JSONArray) obj;
System.out.println(array.get(0));
这个输出:
{"a":1,"b":2}
我的问题是如何从这个二维矩阵中提取键值来输出:
'{ "a": [1,null,5], "b": [2,3,null], "c": [null,4,6] }'
请注意,行中缺少的任何变量都应插入 null...
【问题讨论】:
标签: java json json-simple