2

我有一个 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("作者","urn:li:person:12345");

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

...很快

谢谢。

4

1 回答 1

3

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

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);
于 2019-08-06T13:37:48.837 回答