Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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
C#
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
Posted
Updated 17-Jan-15 1:56am
v2

1 solution

Read the help carefully: http://james.newtonking.com/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConvert.htm[^]

This line:
C#
d = JsonConvert<devotion>.DeserializeObject(json);</devotion>

should be written like this:
C#
d = JsonConvert.DeserializeObject<devotion>(json);</devotion>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900