- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试反序列化此 JSON 字符串时出现以下异常:
{ "studentName": "John", "studentAge": "20" }
异常(exception):
com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@41d241d2 failed to deserialize json object { "studentName": "John", "studentAge": "20" } given the type java.util.List<...>
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:64)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:92)
这些是我的类(class):
public class School {
Gson gson = new Gson();
String json = ...// I can read json from text file, the string is like { "className": "Math", "classTime": "2013-01-01 11:00", "studentList": { "studentName": "John", "studentAge": "20" }}
CourseInfo bean = gson.fromJson(json, CourseInfo.class);
}
类(class)信息.java:
public class CourseInfo implements Serializable {
private static final long serialVersionUID = 1L;
private String className;
private Timestamp classTime;
private List<StudentInfo> studentList;
...
}
StudentInfo.java
public class CourseInfo implements Serializable {
private static final long serialVersionUID = 1L;
private String studentName;
private String studentAge;
...
}
最佳答案
您正在尝试读取一些与您尝试读取的对象不对应的 JSON。具体来说,JSON 中的 studentList
值是一个对象:
{
"studentName": "John",
"studentAge": "20"
}
但是,您正在尝试将该对象读入列表中。鉴于该变量名为 studentList
,我猜想 JSON 是错误的,而不是您的代码,它应该是一个数组:
{
"className": "Math",
"classTime": "2013-01-01 11:00",
"studentList": [
{
"studentName": "John",
"studentAge": "20"
}
]
}
关于java - JsonParseException : Fail to Deserializer JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395229/
我的应用使用 Jackson。我得到的最小化构建主要使用此配置: # don't obfuscate Jackson classes -keep class com.fasterxml.** { *;
编辑:在我问这个问题的那一刻,我想到了尝试一些事情..我已经根据请求设置了 XmlNamespace 属性,这就成功了.. request.XmlNamespace = "http://musicbr
我使用可序列化和可反序列化的泛型。但是,Deserialize上有错误派生属性告诉无法推断类型。 struct 和 enum 都会抛出编译错误。评论其中之一不会解决任何问题。 use serde::{
passport.socketio 抛出此错误,同时无法授权用户。 Error: Error: Failed to deserialize user out of session 我已将问题范围缩小到
我正在尝试在具有借用内容的结构上派生反序列化: #[macro_use] extern crate serde_derive; use std::net::SocketAddr; #[derive(H
我执行查询以创建下面的Hive表: CREATE TABLE db1.test_create_tbl( column1 smallint COMMENT 'desc of column') COMME
这个问题在这里已经有了答案: Can System.Text.Json.JsonSerializer serialize collections on a read-only property? (
我正在使用 event_emmiter_rs用于我的应用程序中的事件处理。该库允许您订阅带有回调的事件并触发这些事件。事件采用 (strings, value) 的形式,回调采用接受值参数的闭包形式。
我收到一个错误...(不存在像默认构造函数这样的创建者):无法从对象值反序列化(没有基于委托(delegate)或基于属性的创建者),这表明我需要一个属性基于的创作者。我有几个具有不同参数但没有默认值
我相信我们需要一个自定义的反序列化器来对我们类的一个字段做一些特定的事情。看来一旦我这样做了,我现在负责反序列化所有其他领域。有没有办法让 jackson 反序列化除了我在这里关心的领域之外的所有领域
我有一个如下所示的类(class) class Person { Long id; String firstName; int age; } 我的输入看起来像这样: { "id
文档建议 NancyFx 帮助我解决 json 请求正文的 WRT 反序列化,但我不确定如何。请参阅下面的测试以演示: [TestFixture] public class ScratchNancy
考虑代码... using System; using System.Text.Json; public class Program { public static void Main()
有人让Deserializer工作吗?我正在方法“反序列化”而不是元素中获得完整的JSON表达式? public static void main(String[] args) { G
在尝试从 tokio TcpStream 反序列化为 JSON Value 时,我正在尝试使用此函数: use futures::prelude::*; use serde_json::Value;
我使用 Spring Boot 和 thymeleaf我尝试保存对象列表。 我的对象。 public class GECPD { public Integer id; public S
我正在尝试制作在线领唱。我需要从外部API获取包含货币值的表,正是从该页面:http://api.nbp.pl/api/exchangerates/tables/A?format=json我想在货币课
错误: java.lang.ClassNotFoundException: testprocedure.tp$3 at java.net.URLClassLoader$1.run(Unknown So
我开发了多个 GWT Web 应用程序。最新的一个是对另一个的稍微修改。除了最新的之外,所有这些都运行良好。异常(exception)是: The response could not be dese
我需要反序列化 1.5GB txt 文件。我正在使用 code.google.com/p/protobuf-net/中的 protobuf-net 有时它会因不同地方的不同异常(空引用、内存访问冲突)
我是一名优秀的程序员,十分优秀!