9

メッセージ要素を持つ Json オブジェクトを受け取るエンドポイントがあり、残りは異なるプロパティを持つことができます。次に例を示します。

public void SendMessage(IDictionary<string, string> message)
{
    var client = new RestClient(MahUrl);
    var request = new RestRequest(Method.POST);
    var json = new JObject();

    foreach (var pair in message)
    {
        json.Add(pair.Key, pair.Value);
    }
    json = new JObject(new JProperty("message", json));
    // {
    //     "message":
    //     {
    //         "prop1": "val1",
    //         "foo": "bar",
    //         "batman": "robin"
    //     }
    // }

    // not quite sure here
    request.?

    // send request
}

.Net オブジェクトをシリアル化/逆シリアル化する方法の例をたくさん見てきましたが、ご覧のとおり、json オブジェクトのプロパティは何でもかまいません。RestSharp を使用して生の json を投稿するにはどうすればよいですか?

4

1 に答える 1

11

次のスニペットが探しているものだと思います。

request.AddParameter("application/json", json, ParameterType.RequestBody);
于 2014-01-28T13:15:41.587 に答える