Json.NET Codeplex:http://www.codeplex.com/json
Originally felt Newtonsoft.json and. NET own javascriptserializer is similar, so the project JSON is replaced by JavaScriptSerializer to achieve, But in recent days there has been a demand. I don't have a pre-defined class in deserialization, but I want to read it in a dictionary.
So I implemented a class myself, because there is no model object, so all the JSON reading and detection process must be re-written.
I later found out that Newtonsoft has provided the functionality I need and even provided a JSON LINQ query.
Jobject
Let's use an example to get it read and write.
1.Json is like this.
{title:123,body:456,list:{title: ' This is a title ', Body: ' What '}}
2. I want to put a few of them out, code:
void Main (string[] args) {string str = "{title:123,body:456,list:{title: ' This is a title ', Body: ' What '}}"; Jobject o = jobject.parse (str); Console.WriteLine (o["title"]); Console.WriteLine (o["Body"]); Console.WriteLine (o["list" ["title"]); Console.WriteLine (o["list" ["Body"]); Console.readkey ();}
3. This outputs the following:
123456 " This is a title" "What"
Insufficient: string or case string output with "", but I think this is not a problem. Trim's fine.
Linq to Json
Basic LINQ is similar, you can refer to the Json.NET documentation. This is not a thorough study.
String str = "{title:123,body:456,list:{title: ' This is a title ', Body: ' What '}}"; Jobject o = jobject.parse (str); var s = In o.children () Select P;foreach (ins) {Console.WriteLine (item);} Console.readkey ();
JSON Learning: http://www.w3school.com.cn/json/json_intro.asp
<HTML><Body><H2>Create a JSON object in JavaScript</H2><P>Name:<spanID= "Jname"></span><BR/>Age :<spanID= "Jage"></span><BR/>Address:<spanID= "Jstreet"></span><BR/>Phone:<spanID= "Jphone"></span><BR/></P><Scripttype= "Text/javascript">varJsonobject= {"name":"Bill Gates","Street":"Fifth Avenue New York 666"," Age": About,"Phone":"555 1234567"};d Ocument.getelementbyid ("Jname"). InnerHTML=JSONObject.namedocument.getElementById ("Jage"). InnerHTML=JSONObject.agedocument.getElementById ("Jstreet"). InnerHTML=JSONObject.streetdocument.getElementById ("Jphone"). InnerHTML=Jsonobject.phone</Script></Body></HTML>
JSON in Jobject