首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“RestClient”不包含“JsonSerializer”的定义,也不包含扩展方法“JsonSerializer”

“RestClient”不包含“JsonSerializer”的定义,也不包含扩展方法“JsonSerializer”
EN

Stack Overflow用户
提问于 2017-04-19 03:47:03
回答 3查看 5.7K关注 0票数 4

当我阅读readme.txt获得最新的RestSharp时:

代码语言:javascript
复制
*** IMPORTANT CHANGE IN RESTSHARP VERSION 103 ***

In 103.0, JSON.NET was removed as a dependency. 

If this is still installed in your project and no other libraries depend on 
it you may remove it from your installed packages.

There is one breaking change: the default Json*Serializer* is no longer 
compatible with Json.NET. To use Json.NET for serialization, copy the code 
from https://github.com/restsharp/RestSharp/blob/86b31f9adf049d7fb821de8279154f41a17b36f7/RestSharp/Serializers/JsonSerializer.cs 
and register it with your client:

var client = new RestClient();
client.JsonSerializer = new YourCustomSerializer();

The default Json*Deserializer* is mostly compatible, but it does not support
all features which Json.NET has (like the ability to support a custom [JsonConverter]
by decorating a certain property with an attribute). If you need these features, you
must take care of the deserialization yourself to get it working.

Im已经在nu包管理器中安装了Newtonsoft.Json,我试图将Json.NET注册到客户端变量,但没有工作。这是我的代码:

代码语言:javascript
复制
private void Form1_Load(object sender, EventArgs e)
        {        
            var client = new RestClient("http://homestead.app/vendor");
            client.JsonSerializer = new JsonSerializer(); <-- HERE IS THE ERROR
            var request = new RestRequest("", Method.GET);
            IRestResponse response = client.Execute(request);
            var content = response.Content; // raw content as string
            textBox1.Text = content;
        }

client.JsonSerializer属性不可用。

请帮帮我。谢谢

EN

Stack Overflow用户

发布于 2017-10-05 12:07:47

新的readme.txt至少在GitHub中被更新,但是包仍然包含旧的代码。

因此,@TcKs的答案是正确的:

代码语言:javascript
复制
var request = new RestRequest();
request.JsonSerializer = new Shared.JsonSerializer();
var client = new RestClient();
client.Post(request);
票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43485991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档