Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Serialization.JSON Class Reference

This class encodes and decodes JSON strings. Spec. details, see http://www.json.org/ More...

Static Public Member Functions

static JSONObject Deserialize (string json)
 Parses the string json into a value More...
 
static string Serialize (JSONObject jsonObject)
 Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string More...
 

Detailed Description

This class encodes and decodes JSON strings. Spec. details, see http://www.json.org/

JSON uses Arrays and Objects. These correspond here to the datatypes IList and IDictionary. All numbers are parsed to doubles.

Definition at line 47 of file JSON.cs.

Member Function Documentation

static JSONObject Hydrogen.Serialization.JSON.Deserialize ( string  json)
static

Parses the string json into a value

Parameters
jsonA JSON string.
Returns
An List<object>, a Dictionary<string, object>, a double, an integer,a string, null, true, or false

var dict = Json.Deserialize(jsonString) as Dictionary<string,object>;

Debug.Log("deserialized: " + dict.GetType()); Debug.Log("dict['array'][0]: " + ((List<object>) dict["array"])[0]); Debug.Log("dict['string']: " + (string) dict["string"]); Debug.Log("dict['float']: " + (double) dict["float"]); // floats come out as doubles Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs Debug.Log("dict['unicode']: " + (string) dict["unicode"]);

Definition at line 64 of file JSON.cs.

65  {
66  // save the string for debug information
67  return json == null ? null : Parser.Parse (json);
68 
69  }
static string Hydrogen.Serialization.JSON.Serialize ( JSONObject  jsonObject)
static

Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string

Parameters
jsonObjectA Dictionary<string, object> / List<object>
Returns
A JSON encoded string, or null if object 'json' is not serializable

string jsonString = Hydrogen.Serialization.JSON.Serialize(object);

Definition at line 397 of file JSON.cs.

398  {
399  return Serializer.Serialize (jsonObject);
400  }