【问题标题】:"Unrecognized token 'com': was expecting ('true', 'false' or 'null')"“无法识别的令牌'com':期待('true','false'或'null')”
【发布时间】:2018-08-04 08:34:34
【问题描述】:

我已将此 json 转换为字符串以保存在本地数据库中

{
        "type": "file",
        "id": "b665ff0b-5f7b-4991-ae88-ac5054880223",
        "link": {
            "href": "https://s3-eu-west-com/87e9edff-e7bd-49ea-aa7a-8948cac29bc1/b665ff0b-5f7b-4991-ae88-ac5054880223.jpg"
        },
        "file_name": "sony 431.jpg",
        "mime_type": "image/jpeg",
        "file_size": 66727,
        "public": true,
        "meta": {
            "dimensions": {
                "width": 1500,
                "height": 1500
            },
            "timestamps": {
                "created_at": "2018-01-22T11:07:35.527Z"
            }
        },
        "links": {
            "current": "https://api.e-com.com/v2/files/b665ff0b-5f7b-4991-ae88-ac5054880223"
        }
    }

当我通过转换为 JSON 来使用该字符串时,我收到错误提示

“无法识别的令牌'com':期待('true','false'或'null')”

我该如何解决这个错误?

这就是我将这个 json 转换为字符串的方式:

staticFile1.setFile(file.toString());

字符串转json:

File file1 = new ObjectMapper().readValue(file, File.class);

【问题讨论】:

  • 请发布您的代码,您是如何转换的..
  • @SantanuSur 我已添加代码
  • 闻起来像缺少 toString() 覆盖但没有看到代码,这是不可能的。

标签: java android json string-conversion jsonexception


【解决方案1】:

我相信你遇到了这样的错误

无法识别的令牌 'com':期待('true'、'false' 或 'null')\n 在 [来源:(字符串)\“com.jwt.secured.user.ApplicationUser@6d9cce48: 用户名:justiuser;密码保护];启用:真; AccountNonExpired:真;凭据非过期:真; AccountNonLocked:真;未授予任何权限\";第 1 行, 列:4]",

com 与字符串中的包引用有关。在类中给出正确的toString() 实现并使用ObjectMapper().writeValueAsString 转换为字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多