Newtonsoft JSON Compiler Error in VS2008


 

Hi,

I'm trying to read JSON from a stream in VS2008 and getting a compiler error that doesn't exist if I was compiling with VS2019.  The code is as follows:

                JsonSerializer serializer = new JsonSerializer();

                using (var steamReader = new StreamReader(stream))
                {
                    using (var jsonTextReader = new JsonTextReader(steamReader))
                    {
                            SSEvent e = serializer.Deserialize<SSEvent>(jsonTextReader);
                    }
                }
            }

I get the following errors on the line "using (var jsonTextReader = new JsonTextReader(steamReader))"

Error    5    The best overloaded method match for 'Newtonsoft.Json.JsonTextReader.JsonTextReader(System.IO.TextReader)' has some invalid arguments  
Error    6    Argument '1': cannot convert from 'Crestron.SimplSharp.CrestronIO.StreamReader' to 'System.IO.TextReader'   

Any ideas on working around this problem would be greatly appreciated.

Thanks in advance for the help

Jay


 

Hello Jay, looks like your using the wrong newtonsoft lib, you want to use the compact framework one that comes with Crestron, not the system one.


 

Thanks.  Actually, I am using the compact framework.

However, I've worked around the problem.  I used a totally different mechanism for getting the data and deserializing the JSON.

So, my codes working now

Thanks again

Jay

On 11/5/2024 6:21 PM, dontrobthemachina via groups.io wrote:

Hello Jay, looks like your using the wrong newtonsoft lib, you want to use the compact framework one that comes with Crestron, not the system one.


 

If you're in VS2008/CF3.5 land on 3-series processors, here's a basic JSON serialize/deserialize.  Build a class to hold the data types in your config file - in my case it's named Scheduler:

string fname = @"\NVRAM\schedule.json";

// from file
string json = File.ReadToEnd(fname, Encoding.UTF8);
Scheduler sched = JsonConvert.DeserializeObject<Scheduler>(json);

// to file
string json = JsonConvert.SerializeObject(this);
StreamWriter sw = new StreamWriter(fname, sched);
sw.Write(json);
sw.Close();


On Tue, Nov 5, 2024 at 8:38 PM jbasen via groups.io <jay.m.basen=gmail.com@groups.io> wrote:

Thanks.  Actually, I am using the compact framework.

However, I've worked around the problem.  I used a totally different mechanism for getting the data and deserializing the JSON.

So, my codes working now

Thanks again

Jay

On 11/5/2024 6:21 PM, dontrobthemachina via groups.io wrote:
Hello Jay, looks like your using the wrong newtonsoft lib, you want to use the compact framework one that comes with Crestron, not the system one.