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

Public Member Functions

 JSONObject ()
 
 JSONObject (Dictionary< string, string > prepopulate)
 Create a JSONObject and prepopulate it with the values from a Dictionary More...
 
 JSONObject (string json)
 Create a JSONObject from a JSON payload More...
 
string ToString (string fieldName)
 
int ToInt (string fieldName)
 
float ToFloat (string fieldName)
 
bool ToBoolean (string fieldName)
 
JSONObject ToJSON (string fieldName)
 
T[] ToArray< T > (string fieldName)
 

Static Public Member Functions

static implicit operator Vector2 (JSONObject value)
 
static operator JSONObject (Vector2 value)
 
static implicit operator Vector3 (JSONObject value)
 
static operator JSONObject (Vector3 value)
 
static implicit operator Quaternion (JSONObject value)
 
static operator JSONObject (Quaternion value)
 
static implicit operator Color (JSONObject value)
 
static operator JSONObject (Color value)
 
static implicit operator Color32 (JSONObject value)
 
static operator JSONObject (Color32 value)
 
static implicit operator Rect (JSONObject value)
 
static operator JSONObject (Rect value)
 

Public Attributes

Dictionary< string, object > Fields = new Dictionary<string, object> ()
 

Properties

object this[string fieldName] [get, set]
 
string Serialized [get, set]
 

Detailed Description

Definition at line 40 of file JSONObject.cs.

Constructor & Destructor Documentation

Hydrogen.Serialization.JSONObject.JSONObject ( )

Definition at line 44 of file JSONObject.cs.

45  {
46  }
Hydrogen.Serialization.JSONObject.JSONObject ( Dictionary< string, string >  prepopulate)

Create a JSONObject and prepopulate it with the values from a Dictionary

Parameters
prepopulateA Dictionary<string,string> of values

Definition at line 52 of file JSONObject.cs.

53  {
54  foreach (string s in prepopulate.Keys) {
55  Fields.Add (s, prepopulate [s]);
56  }
57  }
Hydrogen.Serialization.JSONObject.JSONObject ( string  json)

Create a JSONObject from a JSON payload

Parameters
jsonThe JSON payload

Definition at line 63 of file JSONObject.cs.

64  {
65  Fields = JSON.Deserialize (json).Fields;
66  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42

Member Function Documentation

static implicit Hydrogen.Serialization.JSONObject.operator Color ( JSONObject  value)
static

Definition at line 180 of file JSONObject.cs.

181  {
182  return new Color (
183  Convert.ToSingle (value ["r"]),
184  Convert.ToSingle (value ["g"]),
185  Convert.ToSingle (value ["b"]),
186  Convert.ToSingle (value ["a"])
187  );
188  }
static implicit Hydrogen.Serialization.JSONObject.operator Color32 ( JSONObject  value)
static

Definition at line 202 of file JSONObject.cs.

203  {
204  return new Color32 (
205  Convert.ToByte (value ["r"]),
206  Convert.ToByte (value ["g"]),
207  Convert.ToByte (value ["b"]),
208  Convert.ToByte (value ["a"])
209  );
210  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Vector2  value)
explicitstatic

Definition at line 128 of file JSONObject.cs.

129  {
130  checked {
131  var o = new JSONObject ();
132  o ["x"] = value.x;
133  o ["y"] = value.y;
134  return o;
135  }
136 
137  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Vector3  value)
explicitstatic

Definition at line 147 of file JSONObject.cs.

148  {
149  checked {
150  var o = new JSONObject ();
151  o ["x"] = value.x;
152  o ["y"] = value.y;
153  o ["z"] = value.z;
154  return o;
155  }
156  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Quaternion  value)
explicitstatic

Definition at line 168 of file JSONObject.cs.

169  {
170  checked {
171  var o = new JSONObject ();
172  o ["x"] = value.x;
173  o ["y"] = value.y;
174  o ["z"] = value.z;
175  o ["w"] = value.w;
176  return o;
177  }
178  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Color  value)
explicitstatic

Definition at line 190 of file JSONObject.cs.

191  {
192  checked {
193  var o = new JSONObject ();
194  o ["r"] = value.r;
195  o ["g"] = value.g;
196  o ["b"] = value.b;
197  o ["a"] = value.a;
198  return o;
199  }
200  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Color32  value)
explicitstatic

Definition at line 212 of file JSONObject.cs.

213  {
214  checked {
215  var o = new JSONObject ();
216  o ["r"] = value.r;
217  o ["g"] = value.g;
218  o ["b"] = value.b;
219  o ["a"] = value.a;
220  return o;
221  }
222  }
static Hydrogen.Serialization.JSONObject.operator JSONObject ( Rect  value)
explicitstatic

Definition at line 234 of file JSONObject.cs.

235  {
236  checked {
237  var o = new JSONObject ();
238  o ["left"] = value.xMin;
239  o ["top"] = value.yMax;
240  o ["width"] = value.width;
241  o ["height"] = value.height;
242  return o;
243  }
244  }
static implicit Hydrogen.Serialization.JSONObject.operator Quaternion ( JSONObject  value)
static

Definition at line 158 of file JSONObject.cs.

159  {
160  return new Quaternion (
161  Convert.ToSingle (value ["x"]),
162  Convert.ToSingle (value ["y"]),
163  Convert.ToSingle (value ["z"]),
164  Convert.ToSingle (value ["w"])
165  );
166  }
static implicit Hydrogen.Serialization.JSONObject.operator Rect ( JSONObject  value)
static

Definition at line 224 of file JSONObject.cs.

225  {
226  return new Rect (
227  Convert.ToByte (value ["left"]),
228  Convert.ToByte (value ["top"]),
229  Convert.ToByte (value ["width"]),
230  Convert.ToByte (value ["height"])
231  );
232  }
static implicit Hydrogen.Serialization.JSONObject.operator Vector2 ( JSONObject  value)
static

Definition at line 121 of file JSONObject.cs.

122  {
123  return new Vector3 (
124  Convert.ToSingle (value ["x"]),
125  Convert.ToSingle (value ["y"]));
126  }
static implicit Hydrogen.Serialization.JSONObject.operator Vector3 ( JSONObject  value)
static

Definition at line 139 of file JSONObject.cs.

140  {
141  return new Vector3 (
142  Convert.ToSingle (value ["x"]),
143  Convert.ToSingle (value ["y"]),
144  Convert.ToSingle (value ["z"]));
145  }
T [] Hydrogen.Serialization.JSONObject.ToArray< T > ( string  fieldName)

Definition at line 246 of file JSONObject.cs.

247  {
248  if (Fields.ContainsKey (fieldName)) {
249  if (Fields [fieldName] is IEnumerable) {
250  List<T> l = new List<T> ();
251  foreach (object o in (Fields[fieldName] as IEnumerable)) {
252  if (l is List<string>)
253  (l as List<string>).Add (Convert.ToString (o));
254  else if (l is List<int>)
255  (l as List<int>).Add (Convert.ToInt32 (o));
256  else if (l is List<float>)
257  (l as List<float>).Add (Convert.ToSingle (o));
258  else if (l is List<bool>)
259  (l as List<bool>).Add (Convert.ToBoolean (o));
260  else if (l is List<Vector2>)
261  (l as List<Vector2>).Add ((Vector2)((JSONObject)o));
262  else if (l is List<Vector3>)
263  (l as List<Vector3>).Add ((Vector3)((JSONObject)o));
264  else if (l is List<Rect>)
265  (l as List<Rect>).Add ((Rect)((JSONObject)o));
266  else if (l is List<Color>)
267  (l as List<Color>).Add ((Color)((JSONObject)o));
268  else if (l is List<Color32>)
269  (l as List<Color32>).Add ((Color32)((JSONObject)o));
270  else if (l is List<Quaternion>)
271  (l as List<Quaternion>).Add ((Quaternion)((JSONObject)o));
272  else if (l is List<JSONObject>)
273  (l as List<JSONObject>).Add ((JSONObject)o);
274  }
275  return l.ToArray ();
276  }
277  }
278  return new T[]{ };
279  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42
bool Hydrogen.Serialization.JSONObject.ToBoolean ( string  fieldName)

Definition at line 97 of file JSONObject.cs.

98  {
99  return Fields.ContainsKey (fieldName) && Convert.ToBoolean (Fields [fieldName]);
100  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42
float Hydrogen.Serialization.JSONObject.ToFloat ( string  fieldName)

Definition at line 92 of file JSONObject.cs.

93  {
94  return Fields.ContainsKey (fieldName) ? Convert.ToSingle (Fields [fieldName]) : 0.0f;
95  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42
int Hydrogen.Serialization.JSONObject.ToInt ( string  fieldName)

Definition at line 87 of file JSONObject.cs.

88  {
89  return Fields.ContainsKey (fieldName) ? Convert.ToInt32 (Fields [fieldName]) : 0;
90  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42
JSONObject Hydrogen.Serialization.JSONObject.ToJSON ( string  fieldName)

Definition at line 113 of file JSONObject.cs.

114  {
115  if (!Fields.ContainsKey (fieldName))
116  Fields.Add (fieldName, new JSONObject ());
117 
118  return (JSONObject)this [fieldName];
119  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42
string Hydrogen.Serialization.JSONObject.ToString ( string  fieldName)

Definition at line 82 of file JSONObject.cs.

83  {
84  return Fields.ContainsKey (fieldName) ? Convert.ToString (Fields [fieldName]) : "";
85  }
Dictionary< string, object > Fields
Definition: JSONObject.cs:42

Member Data Documentation

Dictionary<string, object> Hydrogen.Serialization.JSONObject.Fields = new Dictionary<string, object> ()

Definition at line 42 of file JSONObject.cs.

Property Documentation

string Hydrogen.Serialization.JSONObject.Serialized
getset

Definition at line 102 of file JSONObject.cs.

object Hydrogen.Serialization.JSONObject.this[string fieldName]
getset

Definition at line 68 of file JSONObject.cs.