如何使用 deluge 在 post 请求中发送 'JSON'?

How to send 'JSON' in post request using deluge?

我有一个 JSON 数据,我需要用 POST 方法传递它。我不知道如何将 JSON 数据转换为查询参数。请帮助我如何使用 deluge 在 POST 方法中发送这种类型的 JSON 数据。

     jsonData = {
        "author": "urn:li:person:12345",
        "lifecycleState": "PUBLISHED",
        "specificContent": {
            "com.linkedin.ugc.ShareContent": {
                "shareCommentary": {
                    "text": "Hello World! This is my first Share on LinkedIn!"
                },
                "shareMediaCategory": "NONE"
            }
        },
        "visibility": {
            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
        }
    }

这是我实际尝试过的:

headerData = Map();
headerData.put("Content-Type","application/json charset=utf-8");
headerData.put("X-Restli-Protocol-Version","2.0.0");
headerData.put("x-li-format","json");
//json data
fields = "{\"author\":\"urn:li:person:368964147\",\"lifecycleState\":\"PUBLISHED\",\"specificContent\": {\"com.linkedin.ugc.ShareContent\":{\"shareCommentary\":{\"text\": \"Hello World! This is my first Share on LinkedIn!\"},\"shareMediaCategory\": \"NONE\"}},\"visibility\":{\"com.linkedin.ugc.MemberNetworkVisibility\":\"PUBLIC\"}}";
//info fields;
response = invokeurl
[
    url :"https://api.linkedin.com/v2/ugcPosts"
    type :POST
    parameters:fields
    headers:headerData
    connection:"li"
];
info response;

我预计:

参数=映射();

params.put("author","urn:li:person:12345");

params.put("lifecycleState","PUBLISHED");

...等等

谢谢。

我找到了将 JSON 数据转换为查询参数的泛滥代码。

param = Map();
param.put("author","urn:li:person:YoTjU8Fmfk");
param.put("lifecycleState","PUBLISHED");
specificContent = Map();
ShareContent = Map();
shareCommentary = Map();
shareCommentary.put("text","Hello World! This is my first Share on LinkedIn!");
ShareContent.put("shareCommentary",shareCommentary);
specificContent.put("com.linkedin.ugc.ShareContent",ShareContent);
specificContent.put("shareMediaCategory","NONE");
param.put("specificContent",specificContent);
visibility = Map();
visibility.put("com.linkedin.ugc.MemberNetworkVisibility","PUBLIC");
param.put("visibility",visibility);