2016-07-28 40 views
0

有人可以帮我在下面通过在JSON data身体我HTTP POST电话..有人可以帮助我在身体传递JSON数据HTTP POST调用

{ 
    "name": "ABC", 
    "user": "fl9f03fe24a2c4a4b51a4d75", 
    "data": 
    { 
     "details": "component", 
     "Key": "123", 
     "region": "server-23" 
    } 

} 
+0

你至今尝试过什么?分享你的代码。 –

+0

你在哪里做这个POST调用?你有什么错误吗? –

+0

一个可能的答案是已经在[链接](http://stackoverflow.com/questions/7181534/http-post-using-json-in-java) –

回答

0

因此,这是你的代码(我编辑您的文章请接受它):

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); 
+0

嘿它的工作感谢:) –