JSONObject.parseArray Type[] 踩坑记
2021-01-18 本文已影响0人
团长plus
String gameListStr = "[{\"gameId\":\"1\",\"gameName\":\"哈哈\"},{\"gameId\":\"2\",\"gameName\":\"呵呵\"}]";
Type type = new com.alibaba.fastjson.TypeReference<String>() {}.getType();
Type[] types=new Type[2];
types[0] =type;
types[1] =type;
List<Object> gameList = JSONObject.parseArray(gameListStr,types);
System.out.println(gameListStr);
- 注意点 type 数量必须与 json的list 保持一致
if (lexer.token() != JSONToken.RBRACKET) {
throw new JSONException("syntax error");
}
错误源码
Exception in thread "main" com.alibaba.fastjson.JSONException: syntax error
at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:882)