美文网首页
JSONObject.parseArray Type[] 踩坑记

JSONObject.parseArray Type[] 踩坑记

作者: 团长plus | 来源:发表于2021-01-18 11:32 被阅读0次
 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)

相关文章

网友评论

      本文标题:JSONObject.parseArray Type[] 踩坑记

      本文链接:https://www.haomeiwen.com/subject/nxotzktx.html