Skip to content

Instantly share code, notes, and snippets.

@ibio
Forked from darktable/minijsonjsdemo.js
Created November 28, 2013 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibio/7688272 to your computer and use it in GitHub Desktop.
Save ibio/7688272 to your computer and use it in GitHub Desktop.
#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