本文介绍了错误1非泛型类型“Newtonsoft.Json.JsonConvert”不能与类型参数一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨 当我运行下面代码的构建时,它显示此错误 错误1非泛型类型' Newtonsoft.Json.JsonConvert'不能与类型参数一起使用 请帮助一个合适的解决方案 类:
public class 虔诚 { public string 日期{获得; set ;} public string 标题{获取; set ;} public string Verse { get ; set ;} [JsonProperty( 阅读章节)] public string ReadChapter {获得; set ;} [JsonProperty( 读取文本)] public string ReadText {获得; set ;} [JsonProperty( 一年内的圣经)] public string BibleInOneYear { get ; set ;} public 字符串消息{ get ; set ;} public string Notes { get ; set ;} }Xaml.cs
私人列表<投入>奉献; public App() { InitializeComponent(); // 因为填充费用很昂贵 // 您只想在应用启动时执行一次 devotions = new List< Devotion>(); AddDevotions(); } 受保护 覆盖 void OnNavigatedTo(NavigationEventArgs e) { int index = DateTime.Now.DayOfYear - 1 ; // 列表从0索引 textblock.Text = devotions [index] .Message; // 或其他一些属性 } 私有 void AddDevotions() { for ( int i = 1 ; i < ; = 366 ; i ++) { string filePath = Assets / Dec + i.ToString()+ 。js; Devotion d = ReadJsonFile(filePath); devotions.Add(d); } } public Devotion ReadJsonFile( string JsonfilePath) {投入d = null ; 使用(StreamReader r = new StreamReader(JsonfilePath)) { string json = r.ReadToEnd(); d = JsonConvert< Devotion> .DeserializeObject(json); } return d; }提前感谢您的回复
解决方案仔细阅读帮助: james.newtonking/json/help/index.html?topic = html / T_Newtonsoft_Json_JsonConvert.htm [ ^ ] 此行: d = JsonConvert< devotion> ; .DeserializeObject(json); < / devotion > ;
应该这样写:
d = JsonConvert.DeserializeObject< devotion> (json); < / 奉献 >
Hi When i ran the build of the code below it shows this error "Error 1 The non-generic type 'Newtonsoft.Json.JsonConvert' cannot be used with type arguments" Kindly help with an appropriate solution Class:
public class Devotion { public string Date {get; set;} public string Title {get; set;} public string Verse {get; set;} [JsonProperty("Read Chapter")] public string ReadChapter {get; set;} [JsonProperty("Read Text")] public string ReadText {get; set;} [JsonProperty("Bible In One Year")] public string BibleInOneYear {get; set;} public string Message {get; set;} public string Notes {get; set;} }Xaml.cs
private List<Devotion> devotions; public App() { InitializeComponent(); // as this will be expensive to populate // you only want to do it once when the app starts devotions = new List<Devotion>(); AddDevotions(); } protected override void OnNavigatedTo(NavigationEventArgs e) { int index = DateTime.Now.DayOfYear - 1; // list is indexed from 0 textblock.Text = devotions[index].Message; // or some other property } private void AddDevotions() { for(int i = 1; i <= 366; i++) { string filePath = "Assets/Dec" + i.ToString() + ".js"; Devotion d = ReadJsonFile(filePath); devotions.Add(d); } } public Devotion ReadJsonFile(string JsonfilePath) { Devotion d = null; using (StreamReader r = new StreamReader(JsonfilePath)) { string json = r.ReadToEnd(); d = JsonConvert<Devotion>.DeserializeObject(json); } return d; }Thank you in advance and reply soon
解决方案 Read the help carefully: james.newtonking/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConvert.htm[^] This line: d = JsonConvert<devotion>.DeserializeObject(json);</devotion>should be written like this:
d = JsonConvert.DeserializeObject<devotion>(json);</devotion>更多推荐
错误1非泛型类型“Newtonsoft.Json.JsonConvert”不能与类型参数一起使用
发布评论