* LCJsonConverter.cs:
* Common-Unity.csproj: chore
parent
1c70bda35c
commit
8a779af880
|
@ -27,6 +27,9 @@
|
||||||
<Compile Include="..\Common\Task\LCTaskExtensions.cs">
|
<Compile Include="..\Common\Task\LCTaskExtensions.cs">
|
||||||
<Link>Task\LCTaskExtensions.cs</Link>
|
<Link>Task\LCTaskExtensions.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\Common\Json\LCJsonConverter.cs">
|
||||||
|
<Link>Json\LCJsonConverter.cs</Link>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Newtonsoft.Json">
|
<Reference Include="Newtonsoft.Json">
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace LeanCloud.Storage.Internal {
|
|
||||||
public class LCJsonConverter : JsonConverter {
|
|
||||||
public override bool CanConvert(Type objectType) {
|
|
||||||
return objectType == typeof(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
|
||||||
serializer.Serialize(writer, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
|
||||||
if (reader.TokenType == JsonToken.StartObject) {
|
|
||||||
var obj = new Dictionary<string, object>();
|
|
||||||
serializer.Populate(reader, obj);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
if (reader.TokenType == JsonToken.StartArray) {
|
|
||||||
var arr = new List<object>();
|
|
||||||
serializer.Populate(reader, arr);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
if (reader.TokenType == JsonToken.Integer) {
|
|
||||||
if ((long)reader.Value < int.MaxValue) {
|
|
||||||
return Convert.ToInt32(reader.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return serializer.Deserialize(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue