错误1非泛型类型“Newtonsoft.Json.JsonConvert”不能与类型参数一起使用

编程入门 行业动态 更新时间:2024-10-26 07:35:37
本文介绍了错误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”不能与类型参数一起使用

本文发布于:2023-11-15 17:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   能与   错误   参数   非泛型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!