感谢@fge,他为我提供了必要的信息来解决这个问题。
这是我为解决这个问题所做的!
JsonNodeFactory nodeFactory = new JsonNodeFactory();
ObjectNode pushContent = nodeFactory.objectNode();
ObjectNode notification = nodeFactory.objectNode();
ObjectNode appsObj = nodeFactory.objectNode();
ObjectNode target = nodeFactory.objectNode();
ArrayNode apps = nodeFactory.arrayNode();
ArrayNode platforms = nodeFactory.arrayNode();
platforms.add("ios");
appsObj.put("id","app_id");
appsObj.put("platforms",platforms);
apps.add(appsObj);
notification.put("message",filledForm.field("text").value());
notification.put("sound","sounds/alarmsound.wav");
notification.put("target", target);
target.put("apps",apps);
pushContent.put("notification", notification);
pushContent.put("access_token","access_token");
if(!filledForm.field("usage").value().isEmpty()) {
target.put("usage",filledForm.field("usage").value());
}
if(!filledForm.field("latitude").value().isEmpty() && !filledForm.field("longitude").value().isEmpty() && !filledForm.field("radius").value().isEmpty()) {
target.put("latitude",filledForm.field("latitude").value());
target.put("longitude",filledForm.field("longitude").value());
target.put("radius",filledForm.field("radius").value());
}
打印 pushContent 比输出我需要创建的确切 json 对象!
希望这对其他人也有帮助!
富有的