-
-
Save ibio/7688272 to your computer and use it in GitHub Desktop.
This file contains hidden or 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