public class BookDO {
private Long bookId;
private String bookName;
private String authorName;
private Integer wordCount;
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public Integer getWordCount() {
return wordCount;
}
public void setWordCount(Integer wordCount) {
this.wordCount = wordCount;
}
}
String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
解析报错:
com.alibaba.fastjson.JSONException: not close json text, token : string
at com.alibaba.fastjson.parser.DefaultJSONParser.close(DefaultJSONParser.java:1475)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:369)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:269)
3条答案
按热度按时间rmbxnbpk1#
依赖最新fastjson版本
zbsbpyhn2#
缺省parse的顺序是按字母序,需要其他顺序,通过@JSONType指定
wlzqhblo3#
字段中有tab如何处理?
Exception in thread "main" com.alibaba.fastjson.JSONException: 14
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:658)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:365)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:269)