要反序列化JSONArray,您需要使用TypeToken。您可以从GSON用户指南中了解更多信息。示例代码:
@Testpublic void JSON() { Gson gson = new Gson(); Type listType = new TypeToken<List<MyObject>>(){}.getType(); // In this test pre i just shove the JSON here as string. List<Asd> asd = gson.fromJson("[{'name':"test1"}, {'name':"test2"}]", listType);}
如果您有JSONArray,则可以使用
...JSonArray jsonArray = ...gson.fromJson(jsonArray.toString(), listType);...
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)