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