因此,這是你的代碼(我編輯您的文章請接受它):
JSONObject obj = new JSONObject();
obj.put("name", "ABC");
obj.put("user","fl9f03fe24a2c4a4b51a4d75");
datanew = (JSONObject) obj.get("data");
datanew.put("details", "component");
datanew.put("Key", "123");
datanew.put("region","server-23");
你的JSON對象obj
是新的,空的,它不包含任何東西。所以你不能get("data")
之前你put("data")
第一次。試試這個:
JSONObject obj = new JSONObject();
obj.put("name", "ABC");
obj.put("user","fl9f03fe24a2c4a4b51a4d75");
JSONObject datanew = new JSONObject();
datanew.put("details", "component");
datanew.put("Key", "123");
datanew.put("region","server-23");
obj.put("data", datanew);
你至今嘗試過什麼?分享你的代碼。 –
你在哪裏做這個POST調用?你有什麼錯誤嗎? –
一個可能的答案是已經在[鏈接](http://stackoverflow.com/questions/7181534/http-post-using-json-in-java) –