diff options
author | crupest <crupest@outlook.com> | 2022-12-09 18:22:20 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | a586767b9b6e122891a8cddba57aecef11ef4bd2 (patch) | |
tree | 058f34a17aa0cff56c702ace3f84d1918e541789 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs | |
parent | bed807e3f8fab2f8b6ea3409886aac9f23f0f761 (diff) | |
download | crupest-a586767b9b6e122891a8cddba57aecef11ef4bd2.tar.gz crupest-a586767b9b6e122891a8cddba57aecef11ef4bd2.tar.bz2 crupest-a586767b9b6e122891a8cddba57aecef11ef4bd2.zip |
Develop secret api. v21
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs index 5172b34..3017176 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs @@ -1,11 +1,39 @@ using System.Text.Json; -using CrupestApi.Commons.Crud; using Microsoft.Extensions.Options; namespace CrupestApi.Commons; public static class CrupestApiJsonExtensions { + public static object? CheckJsonValueNotArrayOrObject(this JsonElement value) + { + if (value.ValueKind == JsonValueKind.Null && value.ValueKind == JsonValueKind.Undefined) + { + return null; + } + else if (value.ValueKind == JsonValueKind.True) + { + return true; + } + else if (value.ValueKind == JsonValueKind.False) + { + return false; + } + else if (value.ValueKind == JsonValueKind.Number) + { + return value.GetDouble(); + } + else if (value.ValueKind == JsonValueKind.String) + { + return value.GetString(); + } + else + { + throw new Exception("Only value not array or object is allowed.") + } + } + + public static IServiceCollection AddJsonOptions(this IServiceCollection services) { services.AddOptions<JsonSerializerOptions>(); |