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"
}
}
しかし、このペイロードは、私のWebサーバに取得し、コードが「orchestrationFlagsを解析しようとするとき"hashmap、成功しません、代わりにデフォルト値を使用します。私は、Webサーバー上のコードのテストをしたときは、これは、ペイロード構造である私はいつも郵便配達に使ってきたし、それが働いた:
{
"orchestrationFlags": {
"entry": [
{
"key": "overrideStore",
"value": true
},
{
"key": "matchmaking",
"value": true
}
]
},
//requesterSystem and requestedService is the same
}
を私はJSONObjectでこれをachiveできますか? (または別の簡単なAPIを使用しても、インポートはオプションではありません) ありがとう!