Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何使用RestSharp发布原始Json?_.net_Json_Restsharp - Fatal编程技术网

.net 如何使用RestSharp发布原始Json?

.net 如何使用RestSharp发布原始Json?,.net,json,restsharp,.net,Json,Restsharp,我有一个端点,它接受一个带有消息元素的Json对象,其余的可以有不同的属性。下面是一个例子: public void SendMessage(IDictionary<string, string> message) { var client = new RestClient(MahUrl); var request = new RestRequest(Method.POST); var json = new JObject(); foreach (v

我有一个端点,它接受一个带有消息元素的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
}
public void发送消息(IDictionary消息)
{
var client=新的RestClient(MahUrl);
var请求=新的重新请求(Method.POST);
var json=new JObject();
foreach(消息中的var对)
{
Add(pair.Key,pair.Value);
}
json=newjobject(newjproperty(“message”,json));
// {
//“信息”:
//     {
//“prop1”:“val1”,
//“foo”:“bar”,
//“蝙蝠侠”:“罗宾”
//     }
// }
//这里不太清楚
要求
//发送请求
}

我已经看到了一些示例,说明了如何序列化/反序列化.Net对象,但是正如您所看到的,json对象的属性可以是任何东西。如何使用RestSharp发布原始json?

我相信下面的代码片段就是您要寻找的

request.AddParameter("application/json", json, ParameterType.RequestBody);

我也对这个感兴趣。你最终解决了这个问题吗?我放弃了RestSharp。我不得不使用一个标准的HttpWebRequest来发送一条像这样奇怪的消息。当“json”变量是字符串时,这种方法非常有效-我没有尝试向它抛出JObjects。。。(用于查找此页面的其他人的serviceinfo)