请帮助我从以下输出创建主体请求:
{
"categories": [
{
"categoryId": "4654-456465-4564",
"fields": {
"4564654-454646-4564": "Ano",
"4564654-454646-4561": "Super"
}
}
],
"lastUpdate": "1231",
"controlStructureId": "4654-456465-4564",
"controlId": "4654-456465-4564",
"vehicleId": "4654-456465-4564"
}
我的代码在这里,但它不正确,因为我在*fields*部分中有不需要的[]
public void testPOST() {
Map<String, Object> jsonBodyUsingMap = new HashMap<String, Object>();
jsonBodyUsingMap.put("categories", Collections.singletonList(new HashMap<String, Object>() {
{
put("categoryId", "4654-456465-4564");
put("fields", Arrays.asList(new HashMap<String, Object>() {{
put("4564654-454646-4561", "Super");
put("4564654-454646-4564", "Ano");
}}
));
}
}
));
jsonBodyUsingMap.put("lastUpdate", "1231");
jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");
您可以从*fields*中删除Arrays.asList((,只让散列映射
public void testPOST() {
Map<String, Object> jsonBodyUsingMap = new HashMap<String, Object>();
jsonBodyUsingMap.put("categories", Collections.singletonList(new HashMap<String, Object>() {
{
put("categoryId", "4654-456465-4564");
put("fields", new HashMap<String, Object>() {{
put("4564654-454646-4561", "Super");
put("4564654-454646-4564", "Ano");
}}
);
}
}
));
jsonBodyUsingMap.put("lastUpdate", "1231");
jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");
您似乎正在将键/值对象HashMap
包装在Array
方法中。如果你失去了它,你会得到键/值,而不是";括号";(无钥匙值列表(
put("fields", new HashMap<String, Object>() {{
put("4564654-454646-4561", "Super");
put("4564654-454646-4564", "Ano");
}});