为什么要警告Newtonsoft.Json.JsonConvert.DeserializeObjectAsync [英] Why have warning Newtonsoft.Json.JsonConvert.DeserializeObjectAsync

查看:225
本文介绍了为什么要警告Newtonsoft.Json.JsonConvert.DeserializeObjectAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSON.NET版本6.0.1,下面是我的代码

I'm using JSON.NET version 6.0.1 and here my code below

var text = await FileHelper.ReadFileAsync(folderSetting, fileName);
var items = await JsonConvert.DeserializeObjectAsync<ObservableCollection<ItemModel>>(text);

但是我的Visual Studio警告

But my Visual Studio Warning

警告7'Newtonsoft.Json.JsonConvert.DeserializeObjectAsync(string)'已过时:'DeserializeObjectAsync已过时.使用Task.Factory.StartNew方法异步地反序列化JSON:Task.Factory.StartNew(()=> DeserializeObject(value))'

Warning 7 'Newtonsoft.Json.JsonConvert.DeserializeObjectAsync(string)' is obsolete: 'DeserializeObjectAsync is obsolete. Use the Task.Factory.StartNew method to deserialize JSON asynchronously: Task.Factory.StartNew(() => DeserializeObject(value))'

推荐答案

库作者认为提供异步包装不是图书馆的责任,因此将其标记为过时. (请参见 http://blogs.msdn.com/b /pfxteam/archive/2012/03/24/10287244.aspx ).在将来的版本中,这些方法将被删除.您应该改为执行以下操作:

The library authors decided that it was not the responsibility of the library to provide asynchronous wrappers and marked them obsolete. (see http://blogs.msdn.com/b/pfxteam/archive/2012/03/24/10287244.aspx). In future versions these methods will be removed. You should do something like this instead:

var result = await 
    Task.Factory.StartNew(() => JsonConvert.DeserializeObject<MyObject>(jsonText));

这篇关于为什么要警告Newtonsoft.Json.JsonConvert.DeserializeObjectAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆