我使用此代码从 api 获取响应
JsonPath jsonPath = new JsonPath(resp.asString());
我想将这个 jsonPath 对象转换为地图,或者在这一步之前获取响应状态代码,并在转换后将该代码添加到地图中。通过这一步,我只从 api 获取响应正文。 请帮忙 谢谢。
尝试使用一些外部库,例如 jackson,
您可以使用 ObjectMapper 类,如下所示将其转换为地图:
public static Map<String, Object> convert(JsonPath jsonPath) {
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(jsonPath.read(), Map.class);
}