0
json 페이로드로 POST 요청을 보내야합니다. 전체 프로젝트가 가볍기 때문에 간단한 Java 프로젝트이므로 java.net.HttpURLConnection
을 사용하고 있습니다. org.json.JSONObject
. 생성 된 페이로드는 다음과 같습니다새로운 JSONObject (지도 맵)가 원하는 결과를 제공하지 않음
public static String compileSRF() throws JSONException{
Map<String, Boolean> flags = new HashMap<String, Boolean>();
flags.put("overrideStore", true);
flags.put("matchmaking", true);
JSONObject orchestrationFlags = new JSONObject(flags);
JSONObject requesterSystem = new JSONObject();
JSONObject requestedService = new JSONObject();
requesterSystem.put("systemGroup", "testGroup");
requesterSystem.put("systemName", "testSystem");
requesterSystem.put("address", "localhost");
requestedService.put("serviceGroup", "Temperature");
requestedService.put("serviceDefinition", "IndoorTemperature");
List<String> interfaces = new ArrayList<String>();
interfaces.add("json");
requestedService.put("interfaces", interfaces);
JSONObject payload = new JSONObject();
payload.put("requesterSystem", requesterSystem);
payload.put("requestedService", requestedService);
payload.put("orchestrationFlags", orchestrationFlags);
return payload.toString();
}
:
이 방법은 내 페이로드를 컴파일
{
"orchestrationFlags": {
"overrideStore": true,
"matchmaking": true
},
"requesterSystem": {
"address": "localhost",
"systemName": "testSystem",
"systemGroup": "testGroup"
},
"requestedService": {
"interfaces": ["json"],
"serviceGroup": "Temperature",
"serviceDefinition": "IndoorTemperature"
}
}
을하지만이 페이로드 내 웹 서버에 도달하고, 코드는 "orchestrationFlags을 구문 분석 할 때 "hashmap, 성공하지 못하고 대신 기본값을 사용합니다. 나는 웹 서버의 코드에 대한 테스트를했을 때, 이것은 내가 항상 우편 배달에 사용했던 페이로드 구조이며 일 :
{
"orchestrationFlags": {
"entry": [
{
"key": "overrideStore",
"value": true
},
{
"key": "matchmaking",
"value": true
}
]
},
//requesterSystem and requestedService is the same
}
가 어떻게 된 JSONObject와이 achive 수 있습니까? (또는 다른 간단한 API를 사용하지만 가져 오기는 옵션이 아닙니다.) 감사합니다!