如何将jsonarray转换为map或其他可以与datastax值进行比较的格式

时间:2019-06-17 16:06:28

标签: java json rest-assured rest-assured-jsonpath

我有JSON数组,我想将其转换为可以与datastax值进行比较的某种格式。 我尝试了以下代码:

String familyNames = response.jsonPath()。getString(“ FAMILY”);

列出jsonresponse = response.jsonPath()。getList(“ $”);

我找不到任何方法。 我期望可以将整个json响应与datastax表中的值进行比较的格式

1 个答案:

答案 0 :(得分:0)

考虑诸如this onethis one之类的博客,或诸如this one或此here之类的帖子:

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

....
String json = "[{\"name\":\"mkyong\", \"age\":37}, {\"name\":\"fong\", \"age\":38}]";
ObjectMapper mapper = new ObjectMapper();
List<Person> persons = Arrays.asList(mapper.readValue(json, Person[].class));

String jsonString = "{'Bob' : {'name': 'Bob Willis'},"
    + "'Jenny' : {'name': 'Jenny McCarthy'}, "
    + "'Steve' : {'name': 'Steven Waugh'}}";
Gson gson = new Gson();
Type empMapType = new TypeToken<Map<String, Employee>>() {}.getType();
Map<String, Employee> nameEmployeeMap = gson.fromJson(jsonString, empMapType);