【发布时间】:2021-09-18 03:01:20
【问题描述】:
我有一个这样的字符串
"{
"scanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"document": {
"status": "data",
"data": {
"firstName": "FULL NAME",
"info": "{\"city\":\"CITY\",\"issueDate\":\"2019-01-01\"}"
},
"country": "USA"
}
}"
我创建了类(简单 POJO)来将其转换为 java 对象并使用 GSON。我正在使用下面的代码转换为 java 对象。
(gson.fromJson(response, MyClass.class));
但我在转换时收到以下错误,这是因为“info”是一个字符串而不是 json。
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
当我将“info”创建为 json 并对其进行测试时,代码按预期工作,但这里是字符串。
谁能帮我解决这个问题?
PS:谢谢你的帮助。
【问题讨论】:
标签: java spring spring-mvc jackson gson