您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
30 行
825 B
30 行
825 B
using System;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
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 = JsonConvert.DeserializeObject<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 = JsonConvert.SerializeObject (obj);
|
|
}
|
|
|
|
}
|
|
}
|