Created
August 30, 2012 21:54
-
-
Save darktable/3542254 to your computer and use it in GitHub Desktop.
Unity3D: Example of using MiniJSON in UnityScript (JavaScript).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
import MiniJSON; | |
import System.Collections.Generic; | |
function Start () { | |
var jsonString = "{ \"array\": [1.44,2,3], " + | |
"\"object\": {\"key1\":\"value1\", \"key2\":256}, " + | |
"\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " + | |
"\"unicode\": \"\\u3041 Men\\u00fa sesi\\u00f3n\", " + | |
"\"int\": 65536, " + | |
"\"float\": 3.1415926, " + | |
"\"bool\": true, " + | |
"\"null\": null }"; | |
var dict = Json.Deserialize(jsonString) as Dictionary.<String,System.Object>; | |
Debug.Log("deserialized: " + dict.GetType()); | |
Debug.Log("dict['array'][0]: " + ((dict["array"]) as List.<System.Object>)[0]); | |
Debug.Log("dict['string']: " + dict["string"] as String); | |
Debug.Log("dict['float']: " + dict["float"]); // floats come out as doubles | |
Debug.Log("dict['int']: " + dict["int"]); // ints come out as longs | |
Debug.Log("dict['unicode']: " + dict["unicode"] as String); | |
var str = Json.Serialize(dict); | |
Debug.Log("serialized: " + str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I've made another example, but using classes. This way you can use your variable just like in Javascript.
https://gist.github.com/Edudjr/cb407c67e76ac36bcfac#file-classminijson-js