Litjson processing JSON

Source: Internet
Author: User

Litjson is a class library that processes JSON-formatted data in a. NET platform, small and fast. Its source code is written in C # and can be passed by any. NET platform, currently the latest version is Litjson 0.9.

: http://lbv.github.io/litjson/

Unity basically uses this DLL to parse json. Download the DLL into the plugins folder, referencing namespaces using Litjson can be used normally O (∩_∩) o~

Let's look at how JSON is used:

The first parsing of JSON

 Public voidAnalysisJson1 () {strings =@"{' name ': ' Plate face ', ' number ': [' 123 ', ' 456 ']}"; Jsondata Data=LitJson.JsonMapper.ToObject (s); Debug.Log (data["name"]);//output name corresponds to plate face//the value of the loop output array        if(data["Digital"]. IsArray) { for(inti =0; I < data["Digital"]. Count; i++) {Debug.Log (data["Digital"][i]); }        }    }

The second kind of parsing JSON

 Public void AnalysisJson2 ()    {        string@ "{' name ': ' Plate face ', ' number ': [' 123 ', ' 456 ']}";         = LitJson.JsonMapper.ToObject (s);        Debug.Log (data[" number "[0]);        }

The first to create a JSON

 Public voidCreateJson1 () {Hashtable table=NewHashtable (); table["name"] ="Plateface"; string[] STRs =         {            "123",            "456",            "789"        }; table["Digital"] =STRs; stringJSON =Jsonmapper.tojson (table);        Debug.Log (JSON); //Output {"\u6570\u5b57": ["123", "456", "789"], "\u540d\u5b57": "Plateface"}}

The second creation of JSON

 Public voidCreateJson2 () {Jsondata data=NewJsondata (); data["name"] ="Plateface"; data[" Age"] = -; data["Sex"] ="male"; stringJSON =data.        ToJson ();        Debug.Log (JSON); //{"name": "Plateface", "age": +, "sex": "\u7537"}}

The third kind of creating JSON

 Public voidCreateJson3 () {Jsondata data=NewJsondata (); data["name"] ="Plateface"; data["Info"] =NewJsondata (); data["Info"]["Sex"] ="male"; data["Info"][" Age"] = -; stringJSON =data.        ToJson ();        Debug.Log (JSON); //{"name": "Plateface", "info": {"Sex": "Male", "age": +}}}

The fourth type creates JSON

 Public voidCreateJson4 () {plateface P=NewPlateface (); P.name="Plateface"; P.age= A; P.sex="male"; stringJSON =Jsonmapper.tojson (P);                Debug.Log (JSON); //parsing JSONPlateface P2 = jsonmapper.toobject<plateface>(JSON);        Debug.Log (P2.name);    Debug.Log (P2.age); }

Litjson processing JSON

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.