• Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'XXXX': was expecting ('true', 'false' or 'null')


    这个问题是因为前端传值有问题

    jquery ajax代码 

    $.ajax({
    type:"post",
    url:"/webswmm/runModel",
    dataType:'json',
    contentType:"application/json;charset=UTF-8",
    data:{name:'goatling'},
    async:true,
    success:function (data) {
    removeLoading('test');
    showAlertDiologue("success","run");
    resultUrl=data;
    },
    error:function () {
    removeLoading('test');
    showAlertDiologue("fail","run");
    }
    });
    @RequestMapping("/webswmm/runModel")
    @ResponseBody
    public JSONArray runModel(@RequestBody JSONObject jsonObject)
    {

    return dataService.runModel(jsonObject);
    }
    报错:

    JSON parse error: Unrecognized token 'name': was expecting 'null', 'true', 'false' or NaN; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting 'null', 'true', 'false' or NaN
    at [Source: (PushbackInputStream); line: 1, column: 6]
    原因:

    {name:'goatling'} 这种形式根本不是标准JSON字符串

      '{"name":"goatling"}'  这个才是标准JSON字符串

    改正后:

    $.ajax({
    type:"post",
    url:"/webswmm/runModel",
    dataType:'json',
    contentType:"application/json;charset=UTF-8",
    data:'{"name":"goatling"}',
    async:true,
    success:function (data) {
    removeLoading('test');
    showAlertDiologue("success","run");
    resultUrl=data;
    },
    error:function () {
    removeLoading('test');
    showAlertDiologue("fail","run");
    }
    });
    这样才能成功在后台接收到。

  • 相关阅读:
    如何做好接口测试?【转载】
    AutoIT 实现Firefox上传文件
    AutoIT 实现Firefox下载
    测试工具的选择和使用
    JMeter学习参数化User Defined Variables与User Parameters
    JMeter学习(六)集合点
    JMeter学习(五)检查点
    JMeter学习(四)参数化
    JMeter学习(三)元件的作用域与执行顺序
    JMeter学习(二)录制脚本
  • 原文地址:https://www.cnblogs.com/dqiii/p/13159460.html
Copyright © 2020-2023  润新知