JSON 对象使用 java
JSON object using java
我有 json 格式,我想使用 JSONObject 和 JSONArray 在 java 代码中创建它,但我没有得到正确格式的输出。 JSON格式如下
var transaction_Data =
[
{
"key": "PASSED",
"values": [
{"x": "20 June", "y": 30},
{"x": "21 June", "y": 50},
{"x": "22 June", "y": 20},
{"x": "23 June", "y": 60},
{"x": "19 June", "y": 20},
{"x": "24 June", "y": 10}
]
},
{
"key": "FAILED",
"values": [
{"x": "19 June", "y": 50},
{"x": "21 June", "y": 30},
{"x": "20 June", "y": 20},
{"x": "23 June", "y": 70},
{"x": "22 June", "y": 45},
{"x": "24 June", "y": 60}
]
}
]
如何在 java 中创建此 json 对象,因为我想使用此对象使用 NVD3 创建多条形图。非常感谢任何帮助!
you can try it out with this POJOs.
class TransactionData {
private String key;
private List<Data> values;
public TransactionData(String key, List<Data> values) {
this.key = key;
this.values = values;
}
}
class Data {
private String x;
private Integer y;
public Data(String x, Integer y) {
this.x = x;
this.y = y;
}
}
我有 json 格式,我想使用 JSONObject 和 JSONArray 在 java 代码中创建它,但我没有得到正确格式的输出。 JSON格式如下
var transaction_Data =
[
{
"key": "PASSED",
"values": [
{"x": "20 June", "y": 30},
{"x": "21 June", "y": 50},
{"x": "22 June", "y": 20},
{"x": "23 June", "y": 60},
{"x": "19 June", "y": 20},
{"x": "24 June", "y": 10}
]
},
{
"key": "FAILED",
"values": [
{"x": "19 June", "y": 50},
{"x": "21 June", "y": 30},
{"x": "20 June", "y": 20},
{"x": "23 June", "y": 70},
{"x": "22 June", "y": 45},
{"x": "24 June", "y": 60}
]
}
]
如何在 java 中创建此 json 对象,因为我想使用此对象使用 NVD3 创建多条形图。非常感谢任何帮助!
you can try it out with this POJOs.
class TransactionData {
private String key;
private List<Data> values;
public TransactionData(String key, List<Data> values) {
this.key = key;
this.values = values;
}
}
class Data {
private String x;
private Integer y;
public Data(String x, Integer y) {
this.x = x;
this.y = y;
}
}