Horse_Ancheng
2022-04-30 01:40
采纳率: 100%
浏览 66
已结题

springboot 接收复杂的json数据

Springboot接受json数据
问题相关代码

```json数据
[{"q_type":"01","q_must":"1","q_name":"这是名字1","q_option":"[\"2\",\"3\"]","t_id":10017,"t_uid":1},
{"q_type":"02","q_must":"1","q_name":"这是名字2","q_option":"[\"5\",\"6\"]","t_id":10017,"t_uid":1},
{"q_type":"03","q_must":"1","q_name":"这是名字3","q_option":"[]","t_id":10017,"t_uid":1}]
    @CrossOrigin
    @PostMapping("api/newQuestion")
    @ResponseBody //新建问卷
    public JSONObject getJsonVal(@RequestBody JSONObject data) throws IOException {
    JSONObject json = new JSONObject();

//***************************
//只想知道这里怎样获取q_type、q_must、q_name、数组q_option、t_id、t_uid
//***************************

//返回操作结果
        if (flag)
            json.put("msg","success");
        else
            json.put("msg","fail");

        return json;
}

###### 运行结果及报错内容 
2022-04-30 01:18:28.161  WARN 19884 --- [nio-8081-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver :
 Resolved [org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize instance of `com.alibaba.fastjson.JSONObject<java.lang.String,java.lang.Object>`
 out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: 
Cannot deserialize instance of `com.alibaba.fastjson.JSONObject<java.lang.String,java.lang.Object>` 
out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 2]]

1条回答 默认 最新

相关推荐 更多相似问题