java - "Unrecognized token ' com ': was expecting (' 真 ', ' 假 ' or ' 空 ')"

标签 java android json string-conversion jsonexception

我已经把这个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 来使用该字符串时,出现错误提示

"Unrecognized token 'com': was expecting ('true', 'false' or 'null')"

我该如何解决该错误?

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

staticFile1.setFile(file.toString());

和字符串到json:

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

最佳答案

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

Unrecognized token 'com': was expecting ('true', 'false' or 'null')\n at [Source: (String)\"com.jwt.secured.user.ApplicationUser@6d9cce48: Username: justiuser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Not granted any authorities\"; line: 1, column: 4]",

com 与字符串中的包引用相关。在类中提供适当的 toString() 实现,并使用 ObjectMapper().writeValueAsString 将其转换为 String。

关于java - "Unrecognized token ' com ': was expecting (' 真 ', ' 假 ' or ' 空 ')",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48962209/

相关文章:

java - 如何使用 Map.merge 将计数器作为值递增?

java - 如何在 Ivy 中强制使用 HTTPS?

java - 下载文件在 PC 上可以,但在 Android 上只能下载 16kb

android - 通过gson解析json返回null

javascript - 使用子字符串更改数组元素值

javascript - 无法使用nodejs访问json对象的属性

java - [Ljava.lang.StackTraceElement; @ 19821f异常

java - 如何从 GPSD 检索数据并在 Android 客户端中使用它们

android NDK,在另一个android NDK项目中使用已编译的.so库中的函数

php - JSON 或 XML 在 iOS 上性能更好吗?