0
我有一些JSON响应给出了下面的内容。我需要做的是,我需要根据属性名称/键对JSON响应进行排序。示例JSON是,Java - 根据密钥对JSON输出进行排序
{
"cometo-yellow:profiles": {
"upstream-speed-rate-profile": [
{
"name": "default-up-speed-rate-profile",
"maximum-net-speed-rate": 200000,
"maximum-gamma-speed-rate": 200000,
"minimum-expected-throughput": 2000,
"minimum-gamma-speed-rate": 2000
},
{
"name": "test",
"maximum-gamma-speed-rate": 8888,
"minimum-gamma-speed-rate": 2222
}
],
"downstream-speed-rate-profile": [
{
"name": "default-down-speed-rate-profile",
"maximum-net-speed-rate": 800000,
"maximum-gamma-speed-rate": 800000,
"minimum-expected-throughput": 2000,
"minimum-gamma-speed-rate": 2000
}
],
"yellow-rate-adaptation-profile": [
{
"name": "default-yellow-rate-adaptation-profile",
"downstream": {
"minimum-degraded-tones": 1,
"time-window": 8,
"vendor-triggering-criteria-enabled": false,
"uncorrectable-dtu": 150
},
"upstream": {
"minimum-degraded-tones": 1,
"time-window": 8,
"vendor-triggering-criteria-enabled": false,
"uncorrectable-dtu": 150
}
}
]
}
}
上面的JSON需要根据属性进行排序。示例输出如下所示。
{
"cometo-yellow:profiles": {
"downstream-speed-rate-profile": [
"maximum-gamma-speed-rate": 800000,
"maximum-net-speed-rate": 800000
"minimum-expected-throughput": 2000,
"minimum-gamma-speed-rate": 2000,
"name": "default-down-speed-rate-profile"
],
"upstream-speed-rate-profile": [
<<SORTED>>
],
"yellow-rate-adaptation-profile": [
<<SORTED>>
]
}
}
在Java中有这样做的库吗?我们应该怎么做 ?
解析响应成GSON或类似对象后,你可以这样做:http://stackoverflow.com/questions/26568555/sorting-by-property-in-java-8-stream –
使用TreeMap被排序,以便在反序列化时存储地图。 –