搜尋

首頁  >  問答  >  主體

java - Json格式不正確如何修正?

springboot生成的Json格式不正確:
自己生成的格式:
[

{
    "suwd": "24",
    "suyl": "24",
    "jsll": "24",
    "jstds": "24",
    "cstds": "24",
    "ph": "24",
    "yl": "24",
    "ylv": "1",
    "ycy": "24",
    "zd": "24",
    "rjy": "24",
    "d_id": 1,
    "sentem": "20173161723",
    "id": 1
},
{
    "suwd": "83.2",
    "suyl": "62.19",
    "jsll": "67.8",
    "jstds": "46.9",
    "cstds": "33.6",
    "ph": "38.3",
    "yl": "29.8",
    "ylv": "23.5",
    "ycy": "27.32",
    "zd": "29.9",
    "rjy": "28.2",
    "d_id": 1,
    "sentem": "20173161830",
    "id": 2
},
{
    "suwd": "35.67",
    "suyl": "34.65",
    "jsll": "45.67",
    "jstds": "45.89",
    "cstds": "77.56",
    "ph": "34.54",
    "yl": "42.13",
    "ylv": "13.45",
    "ycy": "24.23",
    "zd": "45.56",
    "rjy": "45.54",
    "d_id": 1,
    "sentem": "2017320530",
    "id": 3
},
{
    "suwd": "34",
    "suyl": "35.65",
    "jsll": "45.67",
    "jstds": "57.88",
    "cstds": "34.32",
    "ph": "56.54",
    "yl": "56.98",
    "ylv": "45.76",
    "ycy": "78.65",
    "zd": "67.65",
    "rjy": "23.56",
    "d_id": 1,
    "sentem": "20173201230",
    "id": 4
},
{
    "suwd": "69.78",
    "suyl": "64.45",
    "jsll": "45.76",
    "jstds": "34.78",
    "cstds": "24.45",
    "ph": "24.37",
    "yl": "23.89",
    "ylv": "46.38",
    "ycy": "63.26",
    "zd": "69.73",
    "rjy": "49.69",
    "d_id": 1,
    "sentem": "20173201540",
    "id": 5
},
{
    "suwd": "64.58",
    "suyl": "23.43",
    "jsll": "54.57",
    "jstds": "45.78",
    "cstds": "57.45",
    "ph": "48.59",
    "yl": "45.56",
    "ylv": "34.78",
    "ycy": "23.45",
    "zd": "59.43",
    "rjy": "39.78",
    "d_id": 1,
    "sentem": "20173201723",
    "id": 6
},
{
    "suwd": "54.29",
    "suyl": "34.89",
    "jsll": "58.45",
    "jstds": "49.87",
    "cstds": "45.78",
    "ph": "40.76",
    "yl": "48.87",
    "ylv": "39.98",
    "ycy": "69.45",
    "zd": "58.98",
    "rjy": "34.48",
    "d_id": 1,
    "sentem": "20173202024",
    "id": 7
},
{
    "suwd": "67.89",
    "suyl": "59.70",
    "jsll": "45.78",
    "jstds": "48.89",
    "cstds": "45.87",
    "ph": "56.93",
    "yl": "40.90",
    "ylv": "59.89",
    "ycy": "45.68",
    "zd": "49.99",
    "rjy": "46.90",
    "d_id": 1,
    "sentem": "20173202236",
    "id": 8
},
{
    "suwd": "35.90",
    "suyl": "39.90",
    "jsll": "58.90",
    "jstds": "74.59",
    "cstds": "59.98",
    "ph": "59.98",
    "yl": "69.94",
    "ylv": "48.89",
    "ycy": "49.98",
    "zd": "54.40",
    "rjy": "59.93",
    "d_id": 1,
    "sentem": "20173202339",
    "id": 9
}

]

期望的格式:
"pm25":{

                "key":"",

                "show_desc":0,

                "pm25":{

                    "curPm":"255",

                    "pm25":"227",

                    "pm10":"255",

                    "level":5,

                    "quality":"重度污染",

                    "des":"老年人和心脏病、肺病患者应停留在室内,停止户外活动,一般人群减少户外运动。"

                },

也就是要求大括號前麵要有鍵
這個是在springboot框架下的一串用於輸出Json的代碼
@RestController
@RequestMapping(value = "admin/datas")
public class DatasController {

@Autowired
private ISenddataService senddataService;
@RequestMapping(value = "/{id}",method= RequestMethod.GET)
public List<Senddata> getdatas(@PathVariable Integer id){
    return senddataService.findByDeviceId(id);
}

}

巴扎黑巴扎黑2804 天前765

全部回覆(2)我來回復

  • 阿神

    阿神2017-04-18 10:56:44

    你直接回一個list当然没有key了。用一个Bean包一下就好了。

    回覆
    0
  • 黄舟

    黄舟2017-04-18 10:56:44

    public List<A> getdatas(){...}
    class A{
        private ? key;
        private ? show_desc;
        private B pm25;
    }
    
    class B{
        curPm;
        pm25;
        pm10;
        level;
        quality;
        des;
    }
    

    醬紫?

    回覆
    0
  • 取消回覆