void Start() { GameObject gameState = GameObject.Find("GameState"); GameState gs = gameState.GetComponent <GameState>(); fileName = gs.fileName; String newPath = Path.Combine("StreamingAssets", fileName); // Get Path to file in resources folder without .json ! String savedString = JsonTestClass.LoadJSONFromFile(newPath); // Load Json from file musicFile = new JsonTestClass.MusicalFile(); musicFile = JsonTestClass.JSONToObject(savedString); // Create Object from Json numberNote = musicFile.numberNote; partition = new List <KeyValuePair <NoteScript, float> >(); for (int i = 0; i < numberNote; i++) { int clipIndex = musicFile.musicalNote[i].noteName + 12 * musicFile.musicalNote[i].noteOctave; float clipDuration = musicFile.musicalNote[i].noteTempo; if (clipIndex < 84) { partition.Add(new KeyValuePair <NoteScript, float> (notes [clipIndex].GetComponent <NoteScript> (), clipDuration)); } else { partition.Add(new KeyValuePair <NoteScript, float> (null, clipDuration)); } } // Play(); }
public void Save() { JsonTestClass.MusicalFile musicFile = new JsonTestClass.MusicalFile(); musicFile.numberNote = partition.Count; musicFile.musicalNote = new JsonTestClass.MusicalNote[partition.Count]; for (int i = 0; i < partition.Count; i++) { if (partition [i].NoteToPlay) { musicFile.musicalNote[i] = new JsonTestClass.MusicalNote(partition [i].NoteToPlay.getNoteName(), partition [i].NoteToPlay.Octave - 1, partition [i].nbFourth * 0.25f); } else { musicFile.musicalNote[i] = new JsonTestClass.MusicalNote(0, 10, partition [i].nbFourth * 0.25f); } } String ressourcePath = Path.Combine(Application.dataPath, "Resources"); // Get Path to game resources folder DirectoryInfo di = new DirectoryInfo(Path.Combine(ressourcePath, "StreamingAssets")); // Get Path to Streaming assets int numberFiles = CreateFiles.DirCount(di) / 2; String filePath = Path.Combine("StreamingAssets", "Comp" + numberFiles + ".json"); // Get Path to file in resources folder String realPath = Path.Combine(ressourcePath, filePath); // Get Real Path JsonTestClass.SaveJSONToFile(JsonTestClass.MapToJSON(musicFile), realPath); }
public void WhenNonSerializableTypeThenIsReturnedByGet() { JsonTestClass actual = _distributedCache.Get <JsonTestClass>("json-test"); actual.Should().NotBeNull(); actual.Name.Should().Be("json-test"); }
public async Task WhenNonSerializableTypeThenIsReturnedByGetAsync() { JsonTestClass actual = await _distributedCache.GetAsync <JsonTestClass>("json-test"); actual.Should().NotBeNull(); actual.Name.Should().Be("json-test"); }
public override bool Equals(object obj) { if (obj == null) { return(false); } JsonTestClass jtc = (JsonTestClass)obj; return(true); }
public void JsonStringTest() { Debug.Log(JsonUtility.ToJson(Vector3.zero)); var clas = new JsonTestClass(); clas.x = 123; clas.y = new string[10]; for (int i = 0; i < clas.y.Length; i++) { clas.y[i] = i.ToString(); } Debug.Log(JsonUtility.ToJson(clas)); }
public void WhenNonSerializableTypeThenJsonBytesAreSet() { JsonTestClass testClass = new JsonTestClass { Name = "json-test-xxx" }; byte[] expected = Encoding.UTF8.GetBytes("{\"Name\":\"json-test-xxx\"}"); _distributedCache.Set <JsonTestClass>("json-test", testClass); _mockDistributedCache.Verify( dc => dc.Set( "json-test", It.Is <byte[]>(actual => VerifyBytes(expected, actual)), It.IsAny <DistributedCacheEntryOptions>())); }
public static void RunTest() { JsonTestClass cls = new JsonTestClass(); cls.IntProp = 1; cls.StringProp = "2"; cls.EnumProp = JsonTestEnum.Test3; var sub = new JsonTestSubClass(); sub.LongProp = 4; var sub2 = new JsonTestSubClass(); sub2.LongProp = 5; var sub3 = new JsonTestSubClass(); sub3.LongProp = 6; cls.SubClassProp = sub; sub.ArrayProp = new JsonTestSubClass[2]; sub.ArrayProp[0] = sub2; sub.ArrayProp[1] = sub3; sub.SubClassList = new List <JsonTestSubClass>(); sub.SubClassList.Add(sub2); sub.SubClassList.Add(sub3); cls.DicTest = new Dictionary <string, JsonTestSubClass>(); cls.DicTest["11111"] = sub; cls.DicTest2 = new Dictionary <string, int>(); cls.DicTest2["111222"] = 333444; var str = JsonMapper.ToJson(cls); Debug.Log("---------------"); Debug.Log(str); Debug.Log("---------------"); var cls2 = JsonMapper.ToObject <JsonTestClass>(str); Debug.Log(cls2.SubClassProp.ArrayProp[0].LongProp); Debug.Log(cls2.SubClassProp.ArrayProp[1].LongProp); Debug.Log(cls2.SubClassProp.SubClassList[0].LongProp); Debug.Log(cls2.SubClassProp.SubClassList[1].LongProp); Debug.Log(cls2.DicTest["11111"].LongProp); Debug.Log(cls2.DicTest2["111222"]); }
private void JsonTest() { //Proje içerisinde dâhili json ayrıştırıcı içerir, property isimleri için tırnak kullanımı şart koşulmaz //Ek olarak tek satırlı ve çok satırlı yorumları destekler, doğrudan bir sınıfa atanabilir/sınıftan jsona çevirilebilir. //ExplicitOpetör sayesinde doğrudan string ataması yapılabilir. //veya JsonItem item = JsonDecoder.Decode("{item1: 'değer', 'item2': 'değer'}"); JsonItem item = "{item1: 'değer', 'item2': 'değer'}"; Dictionary <string, object> keys = new Dictionary <string, object>(); //Listeye sonradan bir veriyi JSON formatında ekledik. item.AddSubItem("{item3: 'değer', item4: 'değer'}"); //Verilen nesnenin tipine göre içerisine aktarma yapar. item.ExportTo(ref keys); //Ayrıca dinamik olarakta aşağıdaki şekilde kullanılabilir. dynamic jitem = new JsonItem(); jitem.Item1 = "değer1"; jitem.Item2 = "değer2"; jitem.Item3 = "değer3"; jitem.Item4 = new JsonItem() { }; jitem.Item4.Item1 = "değer2"; string result = jitem.ToString(); JsonItem sinifaAtanacak = "{name: 'macmillan', group: 'AR-GE', Value: 12345, Excluded: 'Bu değer atanmayacak'}"; JsonTestClass testclass = new JsonTestClass(); sinifaAtanacak.ExportTo(ref testclass); //Aynı sınıfı aşağıdaki şekilde JSON a çevirebilirsiniz. JsonItem jsitem = JsonDecoder.DecodeFrom(testclass); string jsonmetni = jsitem.ToString(); //Veya jsitem.ToJson(); }
public void WhenNonSerializableTypeDoesNotExistThenReturnsNull() { JsonTestClass actual = _distributedCache.Get <JsonTestClass>("not-exists"); actual.Should().BeNull(); }
public async Task WhenNonSerializableTypeDoesNotExistThenReturnsNull() { JsonTestClass actual = await _distributedCache.GetAsync <JsonTestClass>("not-exists"); actual.Should().BeNull(); }