-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJSONHelper.cs
More file actions
68 lines (60 loc) · 1.91 KB
/
JSONHelper.cs
File metadata and controls
68 lines (60 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
namespace UnityORM.Helper
{
public static class JSONHelper
{
public static object Array (params object[] values)
{
return values;
}
public static Dictionary<string,object> Dict (params object[] values)
{
Dictionary<string,object> d = new Dictionary<string, object> ();
for (int i = 1; i < values.Length; i += 2)
{
d.Add (values [i - 1].ToString (), values [i]);
}
return d;
}
public static string Jasonize (params object[] dictValues)
{
Dictionary<string,object> d = Dict(dictValues);
return UnityORM.Json.Serialize (d);
}
public static T GetGet<T> (this IDictionary<string,object> dict, string key1, string key2)
{
IDictionary d;
try
{
d = (IDictionary)dict [key1];
if (d == null)
{
Debug.Log ("Key:" + key1 + " not found");
return default(T);
}
}
catch (InvalidCastException e)
{
Debug.LogError ("Wrong cast at key:" + key1 + ";" + e.Message);
return default(T);
}
return (T)d [key2];
}
public static T Get<T> (this IDictionary<string,object> dict, string key)
{
return (T)dict [key];
}
public static IList<object> GetList (this IDictionary<string,object> dict, string key)
{
return (IList<object>)dict [key];
}
public static IDictionary<string,object> GetDict (this IDictionary<string,object> dict, string key)
{
return (IDictionary<string,object>)dict [key];
}
}
}