JSON in Jobject

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.