C# 服务器未识别json,正在使用restSharp发送请求

C# 服务器未识别json,正在使用restSharp发送请求,c#,restsharp,C#,Restsharp,我正在尝试向jboss服务发布一些json。使用restSharp。。我的代码如下 RestClient client = new RestClient(baseURL); RestRequest authenticationrequest = new RestRequest(); authenticationrequest.RequestFormat = DataFormat.Json; authenticationrequest

我正在尝试向jboss服务发布一些json。使用restSharp。。我的代码如下

        RestClient client = new RestClient(baseURL);
        RestRequest authenticationrequest = new RestRequest();
        authenticationrequest.RequestFormat = DataFormat.Json;
        authenticationrequest.Method = Method.POST;
        authenticationrequest.AddParameter("text/json",                  authenticationrequest.JsonSerializer.Serialize(prequestObj), ParameterType.RequestBody);
也试过这个

        RestClient client = new RestClient(baseURL);
        RestRequest authenticationrequest = new RestRequest();
        authenticationrequest.RequestFormat = DataFormat.Json;
        authenticationrequest.Method = Method.POST;                           authenticationrequest.AddBody(authenticationrequest.JsonSerializer.Serialize(prequestObj));

但在这两种情况下,我的服务器都给了我一个错误,json格式不正确

请尝试使用JsonHelper准备json,如下所示

 string jsonToSend = JsonHelper.ToJson(prequestObj);
然后

authenticationrequest.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);

我发现出了什么问题

我正在使用windows metro风格的RestSharp,所以下载了源代码并进行了一些修改。。。所以在函数PutPostInternalAsync中的修改我刚刚添加了这些修改

 httpContent = new StringContent(Parameters[0].Value.ToString(), Encoding.UTF8, "application/json");
它解决了问题


参数[0]。Value.ToString()可以编写一个可以返回序列化json对象的方法来代替它。(作为字符串)。

没有成功,当我检查服务器日志时,它没有在正文中获取json字符串。您能调试您的前传BJ中的值是什么,以及ToJsonon之后的值吗?客户端json的格式正确,但服务器端json的值为空