Introduction
This article is about Newtonsoft JSON deserializing with a C# example. The Newtonsoft.JSON namespace provides classes that are used to implement the core services of the framework. It provides methods for converting between .NET types and JSON types.
Let’s follow the tutorial below to learn how to use newtonsoft.json with C#.
Step 1. Create a database in MySQL with the name “test” and create a table with the name “user”, as shown below.

Step 2. Create a new application project. In Visual Studio, on the menu, click File> New > Project. For more details, see the following menu on the display.

Step 3. Then the window 'New Project' will appear, which should look like the screenshot below.

Step 4. Write down the name of the project that will be created in the field Name. Specify the directory storage project by accessing the field Location. Next, give the name of the solution in the Solution Name. Then click OK.
using System;
using System. collections.Generic;
using System.Linq;
using System.Text;
namespace consoleApplication1
{
class Program
{
static void Main(string[]args)
{
}
}
}
Step 5. Create a new Windows form like the one shown below.

Step 6. Create a new class, “module post,” for requesting json parse from the rest api client. Write the following program listing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;
namespace newtonsoft_json
{
public class modulePost
{
public static string urlServer = "http://localhost/json/ws.php";
public void setURL(string url)
{
urlServer = url;
}
public string getURL()
{
return urlServer;
}
public string Post(string data)
{
string DataFromPHP = null;
try
{
string url = getURL();
byte[] buffer = Encoding.ASCII.GetBytes(data);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.Timeout = 1900000;
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
DataFromPHP = _Answer.ReadToEnd();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return DataFromPHP;
}
}
}


Join the conversation! Your thoughts help the community grow.