diff --git a/Common/Common/Json/LCJsonConverter.cs b/Common/Common/Json/LCJsonConverter.cs index 3e78108..e9b98fd 100644 --- a/Common/Common/Json/LCJsonConverter.cs +++ b/Common/Common/Json/LCJsonConverter.cs @@ -28,6 +28,9 @@ namespace LeanCloud.Common { return Convert.ToInt32(reader.Value); } } + if (reader.TokenType == JsonToken.Float) { + return Convert.ToSingle(reader.Value); + } return serializer.Deserialize(reader); } diff --git a/Storage/Storage.Test/CloudTest.cs b/Storage/Storage.Test/CloudTest.cs index 8cf2d51..53bbaed 100644 --- a/Storage/Storage.Test/CloudTest.cs +++ b/Storage/Storage.Test/CloudTest.cs @@ -28,6 +28,15 @@ namespace Storage.Test { Assert.AreEqual(response["result"], "Hello, world!"); } + [Test] + public async Task RunAverageScore() { + float score = await LCCloud.Run("averageStars", new Dictionary { + { "movie", "夏洛特烦恼" } + }); + TestContext.WriteLine($"score: {score}"); + Assert.True(score.Equals(3.8f)); + } + [Test] public async Task CallWithoutParams() { await LCCloud.Run("hello"); diff --git a/Storage/Storage/LCCloud.cs b/Storage/Storage/LCCloud.cs index a133a3e..99fcdda 100644 --- a/Storage/Storage/LCCloud.cs +++ b/Storage/Storage/LCCloud.cs @@ -36,6 +36,15 @@ namespace LeanCloud.Storage { return response; } + public static async Task Run(string name, + Dictionary parameters = null) { + Dictionary response = await Run(name, parameters); + if (response.TryGetValue("result", out object result)) { + return (T)result; + } + return default; + } + /// /// Invokes a cloud function as a remote procedure call. ///