コード例 #1
0
        public void WriterTest()
        {
            var hGCache = new HGlobalCache <char>();

            var jsonWriter = JsonFormatter.CreateJsonWriter(hGCache);

            jsonWriter.WriteBeginObject();

            jsonWriter.WritePropertyName("Id");

            jsonWriter.WriteInt32(123);

            jsonWriter.WritePropertyName("Name");

            jsonWriter.WriteString("Dogwei");

            jsonWriter.WriteEndObject();

            jsonWriter.Flush();

            var json = hGCache.ToStringEx();

            dynamic dyc = JsonFormatter.DeserializeObject <JsonValue>(json);

            Assert.AreEqual(dyc.Id, 123);
            Assert.AreEqual(dyc.Name, "Dogwei");

            jsonWriter.Clear();

            jsonWriter.WriteBeginArray();

            jsonWriter.WriteInt32(1);
            jsonWriter.WriteInt32(2);
            jsonWriter.WriteInt32(3);

            jsonWriter.WriteEndArray();

            jsonWriter.Flush();

            AreEqual(hGCache.ToStringEx(), "[1,2,3]");
        }