Newtonsoft.json Usage
Newtonsoft.json is the. NET open source Json format sequence number and the deserialized Class library. Official website:
http://json.codeplex.com/
Use Method 1. First download the version you want, and then reference the Newtonsoft.Json.dll file in the application.
2. Reference namespace using Newtonsoft.json; Using Newtonsoft.Json.Linq;
Examples of Use:
String Jsontext = "[{' A ': ' AAA ', ' B ': ' BBB ', ' C ': ' CCC '},{' a ': ' AA ', ' B ': ' BB, ' C ': ' CC '}]";
Jarray ja = (jarray) jsonconvert.deserializeobject (Jsontext);
Jobject o = (jobject) ja[1];
Console.WriteLine (o["A"]);
Console.WriteLine (ja[1]["A"]);
Define an object: VB
String Jsontext = "[{' A ': ' AAA ', ' B ': ' BBB ', ' C ': ' CCC '},{' a ': ' AA ', ' B ': ' BB ', ' C ': ' CC '}]";
list<vb> _list = jsonconvert.deserializeobject<list<vb>> (Jsontext);
Console.WriteLine (_LIST[1].A);
foreach (Customer C in _list)
{
Console.WriteLine (C.C);
} C # uses Newtonsoft.json transform, read, write JSON in. NET
https://www.ibm.com/developerworks/cn/web/wa-lo-json/, here's a brief introduction to JSON:
JSON, or JavaScript Object natation, is a lightweight data interchange format that is ideal for server-to-javascript interaction. As with XML, JSON is also a data format based on plain text. Since JSON is inherently prepared for JavaScript, the JSON data format is very simple, you can transfer a simple string,number,boolean with JSON, or you can transfer an array, or a complex object. Under the. NET environment, we use json.net to serialize and deserialize JSON data. HTTP://SOURCEFORGE.NET/PROJECTS/CSJSON/?SOURCE=DLP Download JSON. NET plug-ins and code. then make a reference in the project Newtonsoft.Json.dllAdd a namespace: using Newtonsoft.json;Here are some important methods and examples of JSON serialization and deserialization:Jsonconvert.serializeobject (object value) serialization, which has an overloaded method Jsonconvert.serializeobject (object value, params Jsonconverter[] converters).
Jsonconvert.deserializeobject (string value, type type), deserialized, which has an overloaded method Jsonconvert.deserializeobject (string value, Type type, params jsonconverter[] converters)
These two methods can implement basic serialization and deserialization requirements, see the following example: public Class Person
{
private string name;
public string Name
{
get {return name;}
set {name = value;}
} private int age;
public int Age
{
get {return age;}
set {age = value;}
}
} using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using Newtonsoft.json; Namespace Jsonnet
{
public partial class Test:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
person person = new person ();
Person. Name = "Goldeneasy";
Person. Age = 25;
String Strserializejson = Jsonconvert.serializeobject (person);
Response.Write (Strserializejson); }
}
} using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using Newtonsoft.json; Namespace Jsonnet
{
public partial class Test:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
person person = new person ();
Person. Name = "Goldeneasy";
Person. Age = 25;
String Strserializejson = Jsonconvert.serializeobject (person);
Person user = (person) jsonconvert.deserializeobject (Strserializejson, typeof (person));
Response.Write (user. Name);
}
}
}the output is: Goldeneasy
Problem: C # Newtonsoft.json use; Result: Newtonsoft.json usage