當前位置: 首頁>>代碼示例>>C#>>正文


C# TestObjects.PersonRaw類代碼示例

本文整理匯總了C#中Newtonsoft.Json.Tests.TestObjects.PersonRaw的典型用法代碼示例。如果您正苦於以下問題:C# PersonRaw類的具體用法?C# PersonRaw怎麽用?C# PersonRaw使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PersonRaw類屬於Newtonsoft.Json.Tests.TestObjects命名空間,在下文中一共展示了PersonRaw類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DeserializeFromRaw

        public void DeserializeFromRaw()
        {
            PersonRaw raw = new PersonRaw
              {
            FirstName = "FirstNameValue",
            RawContent = new JRaw("[1,2,3,4,5]"),
            LastName = "LastNameValue"
              };

              JObject o = JObject.FromObject(raw);

              JsonReader reader = new JTokenReader(o);
              JsonSerializer serializer = new JsonSerializer();
              raw = (PersonRaw)serializer.Deserialize(reader, typeof(PersonRaw));

              Assert.AreEqual("FirstNameValue", raw.FirstName);
              Assert.AreEqual("LastNameValue", raw.LastName);
              Assert.AreEqual("[1,2,3,4,5]", raw.RawContent.Value);
        }
開發者ID:adbre,項目名稱:jsoncf,代碼行數:19,代碼來源:JObjectTests.cs

示例2: JTokenReader

    public void JTokenReader()
    {
      PersonRaw raw = new PersonRaw
      {
        FirstName = "FirstNameValue",
        RawContent = new JRaw("[1,2,3,4,5]"),
        LastName = "LastNameValue"
      };

      JObject o = JObject.FromObject(raw);

      JsonReader reader = new JTokenReader(o);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Raw, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
開發者ID:Jessecar96,項目名稱:Newtonsoft.Json,代碼行數:39,代碼來源:JObjectTests.cs

示例3: FromObjectRaw

    public void FromObjectRaw()
    {
      PersonRaw raw = new PersonRaw
      {
        FirstName = "FirstNameValue",
        RawContent = new JRaw("[1,2,3,4,5]"),
        LastName = "LastNameValue"
      };

      JObject o = JObject.FromObject(raw);

      Assert.AreEqual("FirstNameValue", (string)o["first_name"]);
      Assert.AreEqual(JTokenType.Raw, ((JValue)o["RawContent"]).Type);
      Assert.AreEqual("[1,2,3,4,5]", (string)o["RawContent"]);
      Assert.AreEqual("LastNameValue", (string)o["last_name"]);
    }
開發者ID:Jessecar96,項目名稱:Newtonsoft.Json,代碼行數:16,代碼來源:JObjectTests.cs


注:本文中的Newtonsoft.Json.Tests.TestObjects.PersonRaw類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。