Iterator searchGetResponseIterator = searchGetResponse.entrySet().iterator();
Object obj = null;
Object dataPicker = null;
while(searchGetResponseIterator.hasNext()) {
Map.Entry searchGetResponseElement = (Map.Entry)searchGetResponseIterator.next();
if(searchGetResponseElement.getKey().equals("seSearch")) {
obj = searchGetResponseElement.getValue();
}
}
要在地图中存储"obj"
。在obj中,我有这个>>
{"columns":[{"exp":{"$ali":"t2acName"},"ali":"sourceacName"},"**id**":"4c99eedc836adbeefd0e10db76a","**table**":"public.4c99eedc836adbeefd0e10db76a","fieldIds":["0336e7c7-b236-41b7-8ae8-194dcfc49693","369bc4de-b220-41a2-a7be-090c6386aa2e","37926ca2-044f-44f2-a349-0f2e1b61f120","2310dcca-010f-4830-b300-01fb00d2d15e","306554be-92b3-41a3-bb24-b59f4adc8b79","21cdee98-e3b4-4da9-a502-587c0a221413","1f26c177-944f-4378-9e26-8ee0882221cc","13532fa7-8320-4cc1-90fb-aa8fcc3f5f6f","16d3a857-e8d5-4172-87f5-a149187ec409",],"executionQueue":[{"flow":0,"start":1574674632999,"count":0,"rEnd":1574676432999,"status":"done"},{"flow":0,"start":1574620200000,"count":0,"rEnd":1574674632999,"status":"done"}]}
,我想再次从表格中获取 id 和表格。
答案 0 :(得分:0)
一种更简单的方法是将Object字符串转换为地图并获取字段。
if(searchGetResponseElement.getKey().equals("seSearch")) {
obj = searchGetResponseElement.getValue();
ObjectMapper objectMapper = new ObjectMapper();
HashMap responseMap = objectMapper.readValue(obj.toString(), HashMap.class);
}
拥有responseMap
后,您可以检查该对象并从中获取所需的层次结构。
例如:((Map) ((List) responseMap.get("columns")).get(0)).get("id")
Note:
上面的示例可能无法准确地表示您的响应模型。
答案 1 :(得分:0)
您知道obj的格式
{"**id**":"4c99eedc836adbeefd0e10db76a","**table**":"public.
看起来有一个一致的模式,其中 id 出现,并且 table 出现在字符串/ json的那个斑点中。
查看RegEx Java教程并创建一个以提取ID和表