public static void JsonArray_05_ParseLong() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.CreateJsonArray(); Assert.NotNull(jsonArray); Assert.Equal("[]", jsonArray.ToString()); jsonArray.Insert(0, 100000000000L); var value = jsonArray.ParseLong(0); Assert.Equal(100000000000L, value); jsonArray.Insert(1, "200000000001"); var value2 = jsonArray.ParseLong(1); Assert.Equal(200000000001L, value2); jsonArray.Insert(1, 300000000002L); var value3 = jsonArray.ParseLong(1); Assert.Equal(300000000002, value3); jsonArray.Insert(1, 1); var value4 = jsonArray.ParseLong(1); Assert.Equal(1L, value4); }
public static void Default_6_SerializeObject_WithList() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var classList = new List <TestClass1>(); var class1 = new TestClass1 { TestBool1 = true, TestInt1 = 3, TestString1 = "test" }; classList.Add(class1); var class2 = new TestClass1 { TestInt1 = 5 }; classList.Add(class2); var result = jsonFactory.SerializeObject(classList); Assert.NotNull(result); Assert.Equal("[{\"TestBool1\":true,\"TestInt1\":3,\"TestLong1\":0,\"TestString1\":\"test\"},{\"TestBool1\":false,\"TestInt1\":5,\"TestLong1\":0,\"TestString1\":null}]", result); }
public static void Default_0_GetInstance() { JsonFactory.Register <JsonFactoryImpl>(); var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); }
public void Default_6_SerializeObject_WithListOfDictionary() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var dict = new Dictionary <string, string> { { "testKey0", "testValue0" }, { "testKey1", "testValue1" }, { "testKey2", "testValue2" } }; var dict2 = new Dictionary <string, string> { { "testKey0", "testValue3" }, { "testKey2", "testValue4" }, { "testKey4", "testValue5" } }; var dictList = new List <Dictionary <string, string> > { dict, dict2 }; var result = jsonFactory.SerializeObject(dictList); _output.WriteLine("Serialized string: " + result); Assert.Equal("[{\"testKey0\":\"testValue0\",\"testKey1\":\"testValue1\",\"testKey2\":\"testValue2\"},{\"testKey0\":\"testValue3\",\"testKey2\":\"testValue4\",\"testKey4\":\"testValue5\"}]", result); }
public static void Default_7_DeserializeObject() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var class1 = new TestClass1 { TestBool1 = true, TestInt1 = 3, TestLong1 = 10, TestString1 = "test" }; var result = jsonFactory.SerializeObject(class1); Assert.NotNull(result); Assert.Equal("{\"TestBool1\":true,\"TestInt1\":3,\"TestLong1\":10,\"TestString1\":\"test\"}", result); var deserializedClass1 = jsonFactory.DeserializeObject <TestClass1>(result); Assert.Equal(class1.TestBool1, deserializedClass1.TestBool1); Assert.Equal(class1.TestInt1, deserializedClass1.TestInt1); Assert.Equal(class1.TestLong1, deserializedClass1.TestLong1); Assert.Equal(class1.TestString1, deserializedClass1.TestString1); class1 = new TestClass1 { TestLong1 = 1000000000000 }; result = jsonFactory.SerializeObject(class1); deserializedClass1 = jsonFactory.DeserializeObject <TestClass1>(result); Assert.Equal(class1.TestLong1, deserializedClass1.TestLong1); }
public static void Default_1_CreateJsonArray() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.CreateJsonArray(); Assert.NotNull(jsonArray); Assert.Equal("[]", jsonArray.ToString()); }
public static void JsonArray_00_Size() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); Assert.Equal(0, jsonArray.Size()); }
public static void Default_2_CreateJsonObject() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.CreateJsonObject(); Assert.NotNull(jsonObject); Assert.Equal("{}", jsonObject.ToString()); }
public void JsonObject_18_Unicode() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.CreateJsonObject(); Assert.NotNull(jsonObject); jsonObject.Put("title", "Vive视频"); _output.WriteLine("jsonObject: " + jsonObject); }
public static void JsonObject_16_InsertJsonObject() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); jsonObject = jsonObject.Put("key", new LitJsonJsonFactory.LitJsonJsonObject(JsonMapper.ToObject("{}"))); Assert.NotNull(jsonObject); }
public static void JsonObject_14_PutString() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); jsonObject = jsonObject.Put("key", "test"); Assert.NotNull(jsonObject); }
public static void JsonObject_12_PutInt() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); jsonObject = jsonObject.Put("key", 1); Assert.NotNull(jsonObject); }
public static void JsonObject_09_PutBool() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); jsonObject = jsonObject.Put("key", true); Assert.NotNull(jsonObject); }
public static void Default_5_GetJsonObject() { JsonFactory.Register <JsonFactoryImpl>(); var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); Assert.Equal("{}", jsonObject.ToString()); }
internal bool SaveToFile(Dictionary <string, string> properties) { if (properties == null) { return(false); } if (string.IsNullOrWhiteSpace(_path)) { return(false); } var jsonFactory = JsonFactory.GetInstance(); var jsonObject = jsonFactory.CreateJsonObject(); foreach (var k in properties.Keys) { jsonObject.Put(k, properties[k]); } try { var file = new FileInfo(_path); if (!file.Exists) { var directory = file.Directory; if (directory == null) { return(false); } if (!directory.Exists) { directory.Create(); } } using (var fileStream = File.OpenWrite(file.FullName)) { var bytes = Encoding.UTF8.GetBytes(jsonObject.ToPrettyString()); fileStream.SetLength(0); fileStream.Write(bytes, 0, bytes.Length); } return(true); } catch (IOException e) { Logger.GetInstance(typeof(Storage)).Error(e.Message); } catch (Exception e) { Logger.GetInstance(typeof(Storage)).Error(e.ToString()); } return(false); }
public static void JsonArray_24_InsertJsonObject() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, new LitJsonJsonFactory.LitJsonJsonArray(JsonMapper.ToObject("{}"))); Assert.NotNull(jsonArray); }
public static void Default_4_GetJsonArray() { JsonFactory.Register <JsonFactoryImpl>(); var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); Assert.Equal("[]", jsonArray.ToString()); }
public static void JsonArray_21_InsertLong() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, 100000000000L); Assert.NotNull(jsonArray); }
public static void JsonArray_22_InsertString() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, "test"); Assert.NotNull(jsonArray); }
public static void JsonArray_18_InsertDouble() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, 3.3D); Assert.NotNull(jsonArray); }
public static void JsonArray_19_InsertFloat() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, 2.2F); Assert.NotNull(jsonArray); }
public static void JsonArray_17_InsertBool() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonArray = jsonFactory.GetJsonArray("[]"); Assert.NotNull(jsonArray); jsonArray = jsonArray.Insert(0, true); Assert.NotNull(jsonArray); }
public static void JsonObject_02_ParseDouble_WithDefault() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseDouble("key", 3.3D); Assert.Equal(3.3D, value); }
public static void JsonObject_01_ParseBool_WithDefault() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseBool("key", true); Assert.True(value); }
public static void Default_3_DeserializeObject_WithNull() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var content = ""; var testClass1 = jsonFactory.DeserializeObject <TestClass1>(content); Assert.Null(testClass1); testClass1 = jsonFactory.DeserializeObject <TestClass1>(null); Assert.Null(testClass1); }
public static void JsonObject_03_ParseFloat_WithDefault() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseFloat("key", 2.2F); Assert.Equal(2.2F, value); }
public static void JsonObject_05_ParseLong_WithDefault() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseLong("key", 100000000000L); Assert.Equal(100000000000L, value); }
public static void JsonObject_06_ParseString_WithDefault() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseString("key", "test"); Assert.Equal("test", value); }
public static void JsonObject_08_ParseJsonObject() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.GetJsonObject("{}"); Assert.NotNull(jsonObject); var value = jsonObject.ParseJsonObject("key"); Assert.Null(value); }
public static void JsonObject_00_HasKey() { var jsonFactory = JsonFactory.GetInstance(); Assert.NotNull(jsonFactory); var jsonObject = jsonFactory.CreateJsonObject(); Assert.NotNull(jsonObject); Assert.Equal("{}", jsonObject.ToString()); jsonObject.Put("key", true); Assert.True(jsonObject.HasKey("key")); Assert.False(jsonObject.HasKey("key2")); }