u011652364
小段大帅
2017-10-19 04:11

数据拼装(格式转换)问题

  • java
  • json

源数据格式(list)

 {
            "dataPoint": {
                "value": 1.0,
                "timestamp": 1508208780000
            },
            "resourceId": 11150,
            "resourceName": "duanzhenshuai.sunyainfo.com",
            "metricId": 10720,
            "metricName": "Availability"
        },
        {
            "dataPoint": {
                "value": 0.00530464217547344,
                "timestamp": 1508208600000
            },
            "resourceId": 11150,
            "resourceName": "duanzhenshuai.sunyainfo.com",
            "metricId": 10722,
            "metricName": "Transfer"
        },
        {
            "dataPoint": {
                "value": 0.3743428756508957,
                "timestamp": 1508208600000
            },
            "resourceId": 11150,
            "resourceName": "duanzhenshuai.sunyainfo.com",
            "metricId": 10725,
            "metricName": "CpuUsage"
        }

目的数据格式

 "data": {
    "Availability": "1.0",
    "Transfer": "0.00530464217547344",
    "CpuUsage": "0.3743428756508957"
  }

给出java或json的解决方案都可以,目前只能想到if-else或switch-case判断,但这样如果增添字段会非常麻烦?求指点

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐