如果您的Spring Boot应用程序报告了“Httpmessagebitreadable”错误,这可能是由于您的JSON格式输入参数是一个列表。要传递JSON格式的列表,请使用以下步骤:

  1. 创建一个Java类来表示您的JSON输入参数。例如,如果您的列表包含字符串,则可以创建以下类:
public class StringList {
    private List<String> items;

    public List<String> getItems() {
        return items;
    }

    public void setItems(List<String> items) {
        this.items = items;
    }
}
  1. 在您的控制器方法中使用@RequestBody注释来接收JSON格式的输入参数。例如:
@PostMapping("/items")
public void processItems(@RequestBody StringList stringList) {
    List<String> items = stringList.getItems();
    // 处理您的列表项...
}
  1. 在您的客户端代码中,将列表项放入一个JSON对象中,并将其作为请求正文发送。例如,使用JavaScript:
var items = ["item1", "item2", "item3"];
var data = { "items": items };
var xhr = new XMLHttpRequest();
xhr.open("POST", "/items");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(data));

请注意,这只是一个示例,您需要根据您的应用程序和技术栈进行相应的更改

springboot 报Httpmessagebitreadable错误 json格式入参是list怎么传

原文地址: https://www.cveoy.top/t/topic/hbcP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录