我使用GSON库将列表对象转换为JSON对象。但是,它没有正确创造。
Query query = session.createQuery(hql);
query.setParameter("id", userId);
query.setCacheable(true);
List<?> results = query.list();
Gson gson = new Gson();
String json = gson.toJson(results);
System.out.println("JSON "+json);
[{"id":2,"uid":"123456","widgetModelList":"[{\"name\":\"Icon Feedback\",\"id\":\"7\"},{\"name\":\"My Projects\",\"id\":\"8\"}]","widgetGalleryList":"[{\"name\":\"Icon Feedback\",\"id\":\"7\"},{\"name\":\"My Projects\",\"id\":\"8\"}]","userId":"{\"Id\":\"123456\"}","defaultWidget":"{\"name\":\"Another New Tasks\",\"icon\":\"icon_task\",\"id\":\"4\"}","others":"{\"role\":\"STAFF\",\"todoInDashboard\":true,\"templateURL\":\"views\\/tasks.html\"}"}]
如果我们仔细观察,它会附加&#34;对于值,示例&#34; userId&#34;:&#34; {\&#34; Id \&#34;:\&#34; 123456 \&#34;}&#34; ..这应该就像&#34; userId&#34;:{&#34; Id&#34;:&#34; 123456&#34;} ..该怎么办?我可以使用JSONObject库,但是不可能使用GSON库吗?任何想法