您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
29 行
782 B
29 行
782 B
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace HuaweiService.CloudFunction {
|
|
|
|
public class JsonSerializer {
|
|
public static string ToJson (object obj) {
|
|
JsonModel model = new JsonModel (obj);
|
|
return $"{{\"{model.ClassName}\":{model.ClassValue}}}";
|
|
}
|
|
|
|
public static T FromJson<T> (string json) {
|
|
T m = JsonUtility.FromJson<T>(json);
|
|
return m;
|
|
}
|
|
}
|
|
|
|
public class JsonModel {
|
|
public string ClassName { get; set; }
|
|
public string ClassValue { get; set; }
|
|
public JsonModel () { }
|
|
public JsonModel (object obj) {
|
|
ClassName = obj.GetType ().Name.ToLower ();
|
|
ClassValue = JsonUtility.ToJson(obj);
|
|
}
|
|
|
|
}
|
|
}
|