src/YL.Utils/Json/JsonDict.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using YL.Utils.Check;
using YL.Utils.Extensions;

namespace YL.Utils.Json
{
    public class JsonDict
    {
        private static readonly IDictionary<string, string> _data = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
        private static readonly Stack<string> _context = new Stack<string>();
        private string _currentPath;
        private static JsonTextReader _reader;

        public static IDictionary<string, string> GetKeyValues(string json, EncodingType type = EncodingType.UTF8)
        {
            try
            {
                CheckNull.ArgumentIsNullException(json, nameof(json));
                using (StreamReader streamReader = new StreamReader(json.ToBytes(type).ToStream()))
                {
                    _data.Clear();
                    _reader = new JsonTextReader(streamReader)
                    {
                        DateParseHandling = 0
                    };
                    JObject jObject = JObject.Load(_reader);
                    new JsonDict().VisitJObject(jObject);
                    return _data;
                }
            }
            catch (Exception)
            {
                throw new FormatException("json格式不正确");
            }
        }

        public static IDictionary<string, string> GetKeyValuesFromPath(string path, EncodingType type = EncodingType.UTF8)
        {
            try
            {
                CheckNull.ArgumentIsNullException(path, nameof(path));
                using (StreamReader streamReader = new StreamReader(path, BytesExt.GetEncoding(type)))
                {
                    _data.Clear();
                    _reader = new JsonTextReader(streamReader)
                    {
                        DateParseHandling = 0
                    };
                    JObject jObject = JObject.Load(_reader);
                    new JsonDict().VisitJObject(jObject);
                    return _data;
                }
            }
            catch (Exception)
后面还有 81 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。