我在套接字上傳遞這些資料,并且我在 Hashmap 的 Hashmap 中有資料。我試圖通過它但無法獲取。如何在Hashmap的Hashmap的套接字上傳遞資料。像下面
{"bot_id":"a0ddc016-bcb1-4c41-a2ba-9d2c3a6a1763","curr_id":"99501f27-54c7-4c0a-9b9b-598a5c71d374","data":{"target_id":"59f0048b-b497-4c6f-afb3 -1457d54ba847"},"first_name":"System","last_name":"Message","room_id":"b3d026de-2c13-438b-a8c4-8f40c3d67b2a","user":"bot"}
我無法在套接字上傳遞這個。“資料”:{“target_id”:“59f0048b-b497-4c6f-afb3-1457d54ba847”},
公共無效showToken(TokanGenerationModal jsonObject){
targetId=jsonObject.getTargetId().toString();
room_id=jsonObject.getRoom_id().toString();
owner_Id=jsonObject.getOwner_id().toString();
curr_id=jsonObject.getId();
Map<String,String> appLeadHashMap = new HashMap<>();
appLeadHashMap.put("bot_Id", bot_Id);
appLeadHashMap.put("curr_id", curr_id);
appLeadHashMap.put("first_name","System");
appLeadHashMap.put("last_name","Message");
appLeadHashMap.put("room_id",room_id);
appLeadHashMap.put("user","bot");
appLeadHashMap.put("data",dataHashMap.put("targetId",targetId));
start(owner_Id, room_id);
session_id=jsonObject.getSession_token().toString();
if((NetworkUtilities.isInternet(this)))
{
tokenPresenter.getMessage(targetId,room_id,session_id,this);
}
else
{
Toast.makeText(this, "Check Internet connectivity.", Toast.LENGTH_SHORT).show();
}
}
uj5u.com熱心網友回復:
所以你有兩個HashMaps:appLeadHashMap并且dataHashMap你想把秒作為一個值放在第一個中?
好吧,您appLeadHashMap的HashMap<String,String>意思是它只會接受String值!它不會接受一個HashMap值。
要使這項作業修改您appLeadHashMap以接受任何值:
Map<String,Object> appLeadHashMap = new HashMap<>();
此行的代碼中還有一個令人討厭的錯誤:
appLeadHashMap.put("data",dataHashMap.put("targetId",targetId));
在這里,您將put方法的結果添加到您的哈希映射中,而不是它dataHashMap本身。看起來您想先將鍵值對添加到內部哈希映射中,然后再將其添加到我們的哈希映射中。為此,請使用以下命令:
Map<String,Object> appLeadHashMap = new HashMap<>();
appLeadHashMap.put("bot_Id", bot_Id);
appLeadHashMap.put("curr_id", curr_id);
appLeadHashMap.put("first_name","System");
appLeadHashMap.put("last_name","Message");
appLeadHashMap.put("room_id",room_id);
appLeadHashMap.put("user","bot");
//add key to dataHashMap first
dataHashMap.put("targetId",targetId)
//finally, add the outer hash map to the inner
appLeadHashMap.put("data", dataHashMap);
請注意,現在您必須轉換從 檢索的物件appLeadHashMap,因為它具有值型別Object。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/436589.html
