zoukankan      html  css  js  c++  java
  • 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");
    }
    });
    这样才能成功在后台接收到。

  • 相关阅读:
    图片延时加载LazyLoad真的是LazyLoad吗?
    IO流操作实现文件拷贝\简单加密及相关知识点
    浅谈WebService开发(一)
    一次网站被挂恶意代码的查错经历
    自测,我的优点与缺点
    共鸣,此话在中国的确有些道理
    VsAddIn "Region this"
    虹影图片下载器(Preview)
    Group != Team
    同感,不转不行 低调做人,高调做事
  • 原文地址:https://www.cnblogs.com/dqiii/p/13159460.html
Copyright © 2011-2022 走看看