using Newtonsoft.Json;
using System.Threading.Tasks;
namespace LeanCloud.Common {
///
/// 为 Json 解析提供异步接口
///
public static class JsonUtils {
public static async Task SerializeObjectAsync(object obj) {
string str = null;
await Task.Run(() => {
str = JsonConvert.SerializeObject(obj);
});
return str;
}
public static Task SerializeAsync(object obj) {
return Task.Run(() => {
return JsonConvert.SerializeObject(obj);
});
}
public static async Task DeserializeObjectAsync(string str, params JsonConverter[] converters) {
T obj = default;
await Task.Run(() => {
obj = JsonConvert.DeserializeObject(str, converters);
});
return obj;
}
public static Task DeserializeAsync(string str, params JsonConverter[] converts) {
return Task.Run(() => {
return JsonConvert.DeserializeObject(str, converts);
});
}
}
}