-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntrop_JsonUtility.cs
More file actions
34 lines (32 loc) · 957 Bytes
/
Introp_JsonUtility.cs
File metadata and controls
34 lines (32 loc) · 957 Bytes
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
using Newtonsoft.Json;
namespace UnityEngine.AddressableAssets.Utility
{
public class JsonUtility
{
public static object FromJson(string json, Type type)
{
object result;
if (string.IsNullOrEmpty(json))
{
result = null;
}
else
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (type.IsAbstract || type.IsSubclassOf(typeof(object)))
{
throw new ArgumentException("Cannot deserialize JSON to new instances of type '" + type.Name + ".'");
}
result = JsonConvert.DeserializeObject(json, type);
}
return result;
}
public static string ToJson(object obj)
{
return JsonConvert.SerializeObject(obj);
}
}
}