sending JSON object using POST Methods

允我心安 提交于 2019-12-05 13:41:14
  • "folder = {'name' : 'Test creation folder'}" is invalid JSON. JSON Strings must be enclosed with double-quotes ("). I think you meant this:

    {
        "folder": {
            "name": "Test creation folder"
        }
    }
    
    1. Refer to the JSON specification.
    2. Validate your JSON.
    3. Pretty print your JSON.
  • The correct JSON mime type is application/json.

  • Don't build your JSON by hand. Use the org.json package. Start by looking at JSONObject and JSONArray.

Example:

hc.setRequestProperty("content-type","application/json; charset=utf-8"); 
OutputStreamWriter wr = new OutputStreamWriter(hc.getOutputStream());
JSONObject data = new JSONObject().put("folder",
                  new JSONObject().put("name", "test creation folder"));
wr.write(data.toString());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!