Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft.json JSON.NET

Tags:

c#

json.net

I have found many examples of code for JSON.NET, but I am unable to make any of them run in Visual Studio (C#). Quite probably this is because I am missing something obvious in how to code.

Particularly frustrating is the example code in newtonsoft.com will not compile and run. For example http://www.newtonsoft.com/json/help/html/SerializeObject.htm contains code for 'Types' and 'Usage' but there are no using statements and I can't figure out how to put the code into a project in a way to make it work.

I am sure I am missing something basic I just can't figure it out. I have been Googling for an answer for three days. Can you help me?

like image 257
John Miller Avatar asked Nov 23 '25 17:11

John Miller


1 Answers

Assuming that you have downloaded the Json.NET nuget package (or otherwise properly added Newtonsoft's package to your project and referenced it) the only using statement you need other than the standard ones visual studio adds for you is Newtonsoft.Json

Their code runs perfectly fine in a project of type console application with the following using's:

    using System;                      
    using System.Collections.Generic; 
    using Newtonsoft.Json;

The only other thing you might want to do is add a Console.ReadLine(); at the end so that you can see the output.

like image 155
Ryan McArthur Avatar answered Nov 25 '25 08:11

Ryan McArthur