我有JSON数组,我想将其转换为可以与datastax值进行比较的某种格式。 我尝试了以下代码:
String familyNames = response.jsonPath()。getString(“ FAMILY”);
和
列出jsonresponse = response.jsonPath()。getList(“ $”);
我找不到任何方法。 我期望可以将整个json响应与datastax表中的值进行比较的格式
答案 0 :(得分:0)
考虑诸如this one或this 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);