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); }
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); }
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; }
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)); }
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; }
public string Serialize(Stopwatch timer) { timer.Start(); string s = FastJson.Serialize(jsonData); return("Resulting json is " + s.Length.ToString("n0") + " characters"); }
public string Deserialize(Stopwatch timer) { timer.Start(); Holder list = FastJson.Deserialize <Holder>(jsonText); return("Parsed list is " + list.junkList.Length + " entries long"); }
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; }
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"); }
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)); }
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); }
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"))); }
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); }
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); }
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()); }
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); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); } }
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; }
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; }
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"); }
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); }
/// <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; } }
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); } }
public T TryToObject <T>(string str) { T obj = default(T); try { obj = FastJson.ToObject <T>(str); } catch { return(default(T)); } return(obj); }