**已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
去年关闭了。
Improve this question
下面是我的代码:
assertEquals(
gson.fromJson("[{\"vehicle_side\":\"driver\",\"vehicle_occupant_role\":\"driver\",\"vehicle_window\":\"front_right\",\"window_status\":10.0}]", List.class),
gson.fromJson(myJsonObject, List.class)
);
判断提示失败的原因是:
Expected :[{vehicle_window=front_right, vehicle_occupant_role=driver, window_status=10.0, vehicle_side=driver}]
Actual :[{"vehicle_side":"driver","vehicle_occupant_role":"driver","vehicle_window":"front_right","window_status":10.0}]
为什么我期望的对象包含=
而不是:
?我甚至用硬编码的实际json字符串尝试了一下,但得到了相同的结果:
1条答案
按热度按时间goucqfw61#
默认情况下,
toString()
将':'
Map到'='
。若要解决此问题,请使用从myJsonObject
获取jsonString
并将其传递给gson.fromJson()
。您可以使用ObjectMapper或Gson本身来执行此操作。使用对象Map器:
与Gson: