コード例 #1
0
        protected override void OnConfirm()
        {
            string food = foodType.ToString();

            m_changes[food] = new CookingTime
            {
                name    = "",
                enabled = enabled,
                cooking = cooking,
                burning = burning,
            };
            m_changes.ToList().ForEach(delegate(KeyValuePair <string, CookingTime> x)
            {
                m_food[x.Key] = new CookingTime
                {
                    name    = m_food[x.Key].name,
                    enabled = x.Value.enabled,
                    cooking = x.Value.cooking,
                    burning = x.Value.burning,
                };;
            });
            SaveDataProxy data = new SaveDataProxy
            {
                water = m_water,
                food  = m_food
            };

            string settings = FastJson.Serialize(data);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CookingTweaks.json"), settings);
        }
コード例 #2
0
        private void Test_Example6()
        {
            string testJson = "{\"h_json\":{\"subKey1\":\"subValue1\",\"subKey2\":{\"subKey21\":\"subValue21\"},\"subKey3\":[\"subValue31\",\"subValue32\"]}}";
            ClassH h        = FastJson.Deserialize <ClassH>(testJson);

            Debug.Log(h.json);
        }
コード例 #3
0
        public static void Process(HttpContext context, uint accountId)
        {
            if (!Database.TryGetAccount(accountId, out Account account))
            {
                context.Response.StatusCode = StatusCodes.Status404NotFound;
                return;
            }

            if (SuggestQueryParser.TryParse((QueryCollection)context.Request.Query, ref _query))
            {
                context.Response.ContentType = "application/json";
                if (_query.WillYieldZeroResults)
                {
                    context.Response.ContentLength = FastJson.EmptyAccounts.Length;
                    context.Response.Body.Write(FastJson.EmptyAccounts);
                    return;
                }

                HList <Account> result = _query.Execute(account);

                ParseContext stream = Buffer.Context;
                FastJson.WriteFilterResponse(result, Fields, ref stream, (a, f) => Filter(a, f));

                context.Response.ContentLength = stream.WrittenLength;
                context.Response.Body.Write(stream.WrittenSpan);

                return;
            }

            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
コード例 #4
0
        private void Test_Example2()
        {
            ClassA tempA = new ClassA();

            // 循环嵌套会直接造成崩溃
            //tempA.SetNext(tempA);

            ClassA tempAnotherA = new ClassA();

            tempA.SetA(tempAnotherA);

            ClassB tempB = new ClassB();

            tempA.SetB(tempB);

            ClassC tempC = new ClassC();

            tempA.SetC(tempC);

            tempA.SetGameObject(this.gameObject);

            // 测试 反序列化
            string jsonStr      = FastJson.Serialize(tempA);
            ClassA deserializeA = FastJson.Deserialize <ClassA>(jsonStr);

            Debug.Log(FastJson.Serialize(deserializeA));
        }
コード例 #5
0
        public static void Process(HttpContext context)
        {
            if (FilterQueryParser.TryParse(context.Request.Query, ref _query))
            {
                context.Response.ContentType = "application/json";
                if (_query.WillYieldZeroResults)
                {
                    context.Response.ContentLength = FastJson.EmptyAccounts.Length;
                    context.Response.Body.Write(FastJson.EmptyAccounts);
                    return;
                }

                HList <Account> result = _query.ExecuteFilter();

                ParseContext stream = Buffer.Context;

                FastJson.WriteFilterResponse(result, _query.Fields, ref stream);

                context.Response.ContentLength = stream.WrittenLength;
                context.Response.Body.Write(stream.WrittenSpan);

                return;
            }

            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
コード例 #6
0
    public string Serialize(Stopwatch timer)
    {
        timer.Start();
        string s = FastJson.Serialize(jsonData);

        return("Resulting json is " + s.Length.ToString("n0") + " characters");
    }
コード例 #7
0
    public string Deserialize(Stopwatch timer)
    {
        timer.Start();
        Holder list = FastJson.Deserialize <Holder>(jsonText);

        return("Parsed list is " + list.junkList.Length + " entries long");
    }
コード例 #8
0
ファイル: GroupHandler.cs プロジェクト: solyutor/hlcup2018
        public static void Process(HttpContext context)
        {
            var queryCollection = (QueryCollection)context.Request.Query;

            if (GroupQueryParser.TryParse(queryCollection, ref _query))
            {
                context.Response.ContentType = "application/json";
                if (_query.WillYieldZeroResults)
                {
                    context.Response.ContentLength = FastJson.EmptyGroups.Length;
                    context.Response.Body.Write(FastJson.EmptyGroups);
                    return;
                }

                HList <KeyValuePair <GroupKey, int> > result = _query.ExecuteGroup();


                ParseContext stream = Buffer.Context;
                FastJson.WriteGroupResponse(result, _query, ref stream);

                context.Response.ContentLength = stream.WrittenLength;
                context.Response.Body.Write(stream.WrittenSpan);


                return;
            }

            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
コード例 #9
0
    static public void OnLoad()
    {
        Debug.LogFormat("CookingTweaks: init");

        string        settings = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CookingTweaks.json"));
        SaveDataProxy data     = FastJson.Deserialize <SaveDataProxy>(settings);

        WaterSettings waterSettings = new WaterSettings();
        FoodSettings  foodSettings  = new FoodSettings(data.food.ElementAt(0).Key);

        // m_water = data.water;
        // m_food = data.food;
        //
        // waterSettings.enabled = m_water.enabled;
        // waterSettings.melting = m_water.melting;
        // waterSettings.boiling = m_water.boiling;
        // waterSettings.drying = m_water.drying;
        //
        // string firstFood = ((FoodTypes)0).ToString();
        // foodSettings.foodType = 0;
        // if (!m_food.ContainsKey(firstFood))
        // {
        //     m_food[((FoodTypes)0).ToString()] = GetEmptyStructure();
        // }
        //
        // foodSettings.enabled = m_food[firstFood].enabled;
        // foodSettings.cooking = m_food[firstFood].cooking;
        // foodSettings.burning = m_food[firstFood].burning;
        //
        // waterSettings.AddToModSettings("Cooking Tweaks");
        // foodSettings.AddToModSettings("Cooking Tweaks");
    }
コード例 #10
0
        void Start()
        {
            ExampleClass foo = new ExampleClass();

            foo.id   = 1234;
            foo.name = "SampleClass";

            string jsonText = FastJson.Serialize(foo);

            Debug.Log(jsonText);

            ExampleClass fooDecode = FastJson.Deserialize <ExampleClass>(jsonText);

            Debug.Log("id=" + fooDecode.id + " name=" + fooDecode.name);


            int[][][] bar = new int[][][] {
                new int[][]
                {
                    new int[] { 1 },
                    new int[] { 2, 3 }
                },
                new int[][] {
                    new int[] { 4, 5, 6 }
                },
                null
            };

            jsonText = FastJson.Serialize(bar);
            Debug.Log(jsonText);

            int[][][] barDecode = (int[][][])FastJson.Deserialize(jsonText, typeof(int[][][]));
            Debug.Log(ToString(barDecode));
        }
コード例 #11
0
        protected override void OnConfirm()
        {
            DetectionRange.m_animals["wolf"] = GetSettings();

            string settings = FastJson.Serialize(m_animals);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DetectionRange.json"), settings);
        }
コード例 #12
0
        private static T LoadDataFromJson <T>(T defaultT) where T : IDataBase
        {
            var dataTypeKey = defaultT.GetType().Name;

            return(PlayerPrefs.HasKey(dataTypeKey) == false
                ? defaultT
                : FastJson.Deserialize <T>(PlayerPrefs.GetString(dataTypeKey, "NULL")));
        }
コード例 #13
0
        protected override void OnConfirm()
        {
            TweakRabbits.killOnHit    = killOnHit;
            TweakRabbits.stunDuration = stunDuration;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TweakRabbits.json"), settings);
        }
コード例 #14
0
ファイル: TempDropTweaks.cs プロジェクト: 2sw1ft/TempDrop
            protected override void OnConfirm()
            {
                TempDropOptions.temp_drop_celsius_max = temp_drop_celsius_max;


                string json_opts = FastJson.Serialize(this);

                File.WriteAllText(Path.Combine(mod_options_folder, options_file_name), json_opts);
            }
コード例 #15
0
    static public void OnLoad()
    {
        Debug.LogFormat("DetectionRange: init");

        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DetectionRange.json"));
        Dictionary <string, AnimalRanges> settings = FastJson.Deserialize <Dictionary <string, AnimalRanges> >(opts);

        WolfRangesSettings wolves = new WolfRangesSettings();

        if (!settings.ContainsKey("wolf"))
        {
            settings["wolf"] = GetEmptyStructure();
        }
        wolves.SetSettings(settings["wolf"]);
        wolves.AddToModSettings("Detection Range");
        m_animals.Add("wolf", wolves.GetSettings());

        DeerRangesSettings deers = new DeerRangesSettings();

        if (!settings.ContainsKey("deer"))
        {
            settings["deer"] = GetEmptyStructure();
        }
        deers.SetSettings(settings["deer"]);
        deers.AddToModSettings("Detection Range");
        m_animals.Add("deer", deers.GetSettings());

        MooseRangesSettings mooses = new MooseRangesSettings();

        if (!settings.ContainsKey("moose"))
        {
            settings["moose"] = GetEmptyStructure();
        }
        mooses.SetSettings(settings["moose"]);
        mooses.AddToModSettings("Detection Range");
        m_animals.Add("moose", mooses.GetSettings());

        RabbitRangesSettings rabbits = new RabbitRangesSettings();

        if (!settings.ContainsKey("rabbit"))
        {
            settings["rabbit"] = GetEmptyStructure();
        }
        rabbits.SetSettings(settings["rabbit"]);
        rabbits.AddToModSettings("Detection Range");
        m_animals.Add("rabbit", rabbits.GetSettings());

        BearRangesSettings bears = new BearRangesSettings();

        if (!settings.ContainsKey("bear"))
        {
            settings["bear"] = GetEmptyStructure();
        }
        bears.SetSettings(settings["bear"]);
        bears.AddToModSettings("Detection Range");
        m_animals.Add("bear", bears.GetSettings());
    }
コード例 #16
0
        protected override void OnConfirm()
        {
            FasterActionRedux.containerTime = containerTime;
            FasterActionRedux.actionTime    = actionTime;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FasterActionRedux.json"), settings);
        }
コード例 #17
0
            protected override void OnConfirm()
            {
                GearDecayOptions.general_decay       = general_decay;
                GearDecayOptions.decay_before_pickup = decay_before_pickup;

                string json_opts = FastJson.Serialize(this);

                File.WriteAllText(Path.Combine(mod_options_folder, options_file_name), json_opts);
            }
コード例 #18
0
        protected override void OnConfirm()
        {
            StruggleTweaks.chanceToKillWolfAfterStruggle = chanceToKillWolfAfterStruggle;
            StruggleTweaks.wolfBleedoutMinutes           = wolfBleedoutMinutes;
            StruggleTweaks.tapIncrement = tapIncrement;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "StruggleTweaks.json"), settings);
        }
コード例 #19
0
        protected override void OnConfirm()
        {
            SkipIntroRedux.skipDisclaimer = skipDisclaimer;
            SkipIntroRedux.skipIntro      = skipIntro;
            SkipIntroRedux.skipFade       = skipFade;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SkipIntroRedux.json"), settings);
        }
コード例 #20
0
        protected override void OnConfirm()
        {
            WeaponCrosshair.stoneCrosshair = stoneCrosshair;
            WeaponCrosshair.rifleCrosshair = rifleCrosshair;
            WeaponCrosshair.bowCrosshair   = bowCrosshair;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WeaponCrosshair.json"), settings);
        }
コード例 #21
0
        protected override void OnConfirm()
        {
            TimeAccelerator.accelerationKey   = KeyCode.A + accelerationKey;
            TimeAccelerator.holdToAccelerate  = accelerationBehaviour == 0;
            TimeAccelerator.accelerationValue = accelerationValue;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TimeAccelerator.json"), settings);
        }
コード例 #22
0
ファイル: TempDropTweaks.cs プロジェクト: 2sw1ft/TempDrop
            public static void OnLoad()
            {
                if (File.Exists(Path.Combine(mod_options_folder, options_file_name)))
                {
                    string opts = File.ReadAllText(Path.Combine(mod_options_folder, options_file_name));
                    custom_settings = FastJson.Deserialize <TempDropSettings>(opts);

                    TempDropOptions.temp_drop_celsius_max = custom_settings.temp_drop_celsius_max;
                }

                custom_settings.AddToModSettings("Temperature Drop");
            }
コード例 #23
0
        private static void SaveDataToJson <T>(T data, bool isSaveWithCloud = false) where T : IDataBase
        {
            var saveJson = FastJson.Serialize(data);
            var typeName = data.GetType().Name;

            PlayerPrefs.SetString(typeName, saveJson);

            if (isSaveWithCloud)
            {
                _saveCloudAction?.Invoke(typeName, saveJson);
            }
        }
コード例 #24
0
    static public void OnLoad()
    {
        Debug.LogFormat("FasterActionRedux: init");

        FasterActionReduxSettings settings = new FasterActionReduxSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FasterActionRedux.json"));

        settings = FastJson.Deserialize <FasterActionReduxSettings>(opts);
        settings.AddToModSettings("Faster Actions Redux");

        containerTime = settings.containerTime;
        actionTime    = settings.actionTime;
    }
コード例 #25
0
    static public void OnLoad()
    {
        Debug.LogFormat("TweakRabbits: init");

        TweakRabbitsSettings settings = new TweakRabbitsSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TweakRabbits.json"));

        settings = FastJson.Deserialize <TweakRabbitsSettings>(opts);
        settings.AddToModSettings("Tweak Rabbits");

        killOnHit    = settings.killOnHit;
        stunDuration = settings.stunDuration;
    }
コード例 #26
0
            public static void OnLoad()
            {
                if (File.Exists(Path.Combine(mod_options_folder, options_file_name)))
                {
                    string opts = File.ReadAllText(Path.Combine(mod_options_folder, options_file_name));
                    custom_settings = FastJson.Deserialize <GearDecaySettings>(opts);

                    GearDecayOptions.general_decay       = custom_settings.general_decay;
                    GearDecayOptions.decay_before_pickup = custom_settings.decay_before_pickup;
                }

                custom_settings.AddToModSettings("Xpazeman Mini Mods");
            }
コード例 #27
0
        protected override void OnConfirm()
        {
            MapTweaks.overrideDrawingRange = overrideDrawingRange;
            MapTweaks.drawingRange         = drawingRange;

            // force disable
            MapTweaks.autodrawEnabled = false;
            MapTweaks.autodrawDelay   = autodrawDelay;

            string settings = FastJson.Serialize(this);

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MapTweaks.json"), settings);
        }
コード例 #28
0
ファイル: JsonConfig.cs プロジェクト: zeroyou/X
        /// <summary>加载指定配置文件</summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public virtual Boolean Load(String filename)
        {
            if (filename.IsNullOrWhiteSpace())
            {
                return(false);
            }

            filename = filename.GetBasePath();
            if (!File.Exists(filename))
            {
                return(false);
            }

            _loading = true;
            try
            {
                var data   = File.ReadAllBytes(filename);
                var config = this as TConfig;


                //var json = new Serialization.Json
                //{
                //    Stream = new MemoryStream(data),
                //    UseProperty = true,
                //    Indented = true
                //};

                //if (_.Debug) json.Log = XTrace.Log;

                //Object obj = config;
                var cfg = new FastJson().Read(data.ToStr(), config.GetType());
                config.Copy(cfg);

                //if (!json.TryRead(GetType(), ref obj)) return false;

                config.ConfigFile = filename;
                config.SetExpire();  // 设定过期时间
                config.OnLoaded();

                return(true);
            }
            catch (Exception ex)
            {
                XTrace.WriteException(ex);
                return(false);
            }
            finally
            {
                _loading = false;
            }
        }
コード例 #29
0
        private static void ProcessFile(string path)
        {
            string text = File.ReadAllText(path);

            try
            {
                ModBlueprint blueprint = FastJson.Deserialize <ModBlueprint>(text);
                Mapper.RegisterBlueprint(blueprint, path);
            }
            catch (Exception e)
            {
                throw new System.ArgumentException("Could not read blueprint from '" + path + "'.", e);
            }
        }
コード例 #30
0
        public T TryToObject <T>(string str)
        {
            T obj = default(T);

            try
            {
                obj = FastJson.ToObject <T>(str);
            }
            catch
            {
                return(default(T));
            }
            return(obj);
        }