|
@@ -27,6 +27,7 @@ public class split_names extends UDF {
|
|
for (String json : jsonArr) {
|
|
for (String json : jsonArr) {
|
|
parse(json, json_path, set);
|
|
parse(json, json_path, set);
|
|
}
|
|
}
|
|
|
|
+
|
|
return new ArrayList<>(set);
|
|
return new ArrayList<>(set);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
@@ -35,14 +36,16 @@ public class split_names extends UDF {
|
|
|
|
|
|
public void parse(String json, String json_path, Set set) {
|
|
public void parse(String json, String json_path, Set set) {
|
|
JSONArray jsonArray = ((JSONArray) JSONPath.eval(JSON.parse(json), json_path));
|
|
JSONArray jsonArray = ((JSONArray) JSONPath.eval(JSON.parse(json), json_path));
|
|
- for (Object o : jsonArray) {
|
|
|
|
- set.add(o);
|
|
|
|
|
|
+ for (Object s : jsonArray) {
|
|
|
|
+ if (s != null && s.toString().length() > 0) {
|
|
|
|
+ set.add(s);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
String jsons = "[{\"name\":\"张海林\",\"litigant_id\":\"\"},{\"name\":\"招商银行股份有限公司信用卡中心\",\"litigant_id\":\"cc45eeb0634f73531ba54ad55ba152a6\"}]&[{\"name\":\"上海浦东发展银行静安支行\",\"litigant_id\":\"c2c57fcc6398cfd49393c1a2d3c35a4c\"}]";
|
|
String jsons = "[{\"name\":\"张海林\",\"litigant_id\":\"\"},{\"name\":\"招商银行股份有限公司信用卡中心\",\"litigant_id\":\"cc45eeb0634f73531ba54ad55ba152a6\"}]&[{\"name\":\"上海浦东发展银行静安支行\",\"litigant_id\":\"c2c57fcc6398cfd49393c1a2d3c35a4c\"}]";
|
|
- String json_path = "$.name";
|
|
|
|
|
|
+ String json_path = "$.litigant_id";
|
|
split_names n = new split_names();
|
|
split_names n = new split_names();
|
|
System.out.println(n.evaluate(jsons, json_path));
|
|
System.out.println(n.evaluate(jsons, json_path));
|
|
}
|
|
}
|