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


C# JValue.ToString方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.Linq.JValue.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# JValue.ToString方法的具體用法?C# JValue.ToString怎麽用?C# JValue.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.Linq.JValue的用法示例。


在下文中一共展示了JValue.ToString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ValidateOne

 private ValidationResult ValidateOne(string path, IMetadataDefinition definition, JValue value)
 {
     if (definition.ChoiceSet.Contains(value))
     {
         return ValidationResult.Success;
     }
     return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.UndefinedValue, $"Bad metadata: Value {value.ToString()} is undefined for {path}.", path);
 }
開發者ID:ansyral,項目名稱:docfx,代碼行數:8,代碼來源:WellknownChoiceSetValidator.cs

示例2: ToStringFormat

        public void ToStringFormat()
        {
            JValue v = new JValue(new DateTime(2013, 02, 01, 01, 02, 03, 04));

            Assert.AreEqual("2013", v.ToString("yyyy"));
        }
開發者ID:NiklasGillstrom,項目名稱:Newtonsoft.Json,代碼行數:6,代碼來源:JValueTests.cs

示例3: WriteSingle

        public void WriteSingle()
        {
            float f = 5.2f;
            JValue value = new JValue(f);

            string json = value.ToString(Formatting.None);

            Assert.AreEqual("5.2", json);
        }
開發者ID:NiklasGillstrom,項目名稱:Newtonsoft.Json,代碼行數:9,代碼來源:JValueTests.cs

示例4: JValueToString

        public void JValueToString()
        {
            JValue v;

            v = new JValue(true);
            Assert.AreEqual("True", v.ToString());

            v = new JValue(Encoding.UTF8.GetBytes("Blah"));
            Assert.AreEqual("System.Byte[]", v.ToString(null, CultureInfo.InvariantCulture));

            v = new JValue("I am a string!");
            Assert.AreEqual("I am a string!", v.ToString());

            v = new JValue(null, JTokenType.Null);
            Assert.AreEqual("", v.ToString());

            v = new JValue(null, JTokenType.Null);
            Assert.AreEqual("", v.ToString(null, CultureInfo.InvariantCulture));

            v = new JValue(new DateTime(2000, 12, 12, 20, 59, 59, DateTimeKind.Utc), JTokenType.Date);
            Assert.AreEqual("12/12/2000 20:59:59", v.ToString(null, CultureInfo.InvariantCulture));

            v = new JValue(new Uri("http://json.codeplex.com/"));
            Assert.AreEqual("http://json.codeplex.com/", v.ToString(null, CultureInfo.InvariantCulture));

            v = new JValue(TimeSpan.FromDays(1));
            Assert.AreEqual("1.00:00:00", v.ToString(null, CultureInfo.InvariantCulture));

            v = new JValue(new Guid("B282ADE7-C520-496C-A448-4084F6803DE5"));
            Assert.AreEqual("b282ade7-c520-496c-a448-4084f6803de5", v.ToString(null, CultureInfo.InvariantCulture));

#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
            v = new JValue(BigInteger.Parse("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990"));
            Assert.AreEqual("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990", v.ToString(null, CultureInfo.InvariantCulture));
#endif
        }
開發者ID:NiklasGillstrom,項目名稱:Newtonsoft.Json,代碼行數:36,代碼來源:JValueTests.cs

示例5: EnumTests

        public void EnumTests()
        {
            JValue v = new JValue(StringComparison.Ordinal);
            Assert.AreEqual(JTokenType.Integer, v.Type);

            string s = v.ToString();
            Assert.AreEqual("Ordinal", s);

            StringComparison e = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.Ordinal, e);

            dynamic d = new JValue(StringComparison.CurrentCultureIgnoreCase);
            StringComparison e2 = (StringComparison)d;
            Assert.AreEqual(StringComparison.CurrentCultureIgnoreCase, e2);

            string s1 = d.ToString();
            Assert.AreEqual("CurrentCultureIgnoreCase", s1);

            string s2 = (string)d;
            Assert.AreEqual("CurrentCultureIgnoreCase", s2);

            d = new JValue("OrdinalIgnoreCase");
            StringComparison e3 = (StringComparison)d;
            Assert.AreEqual(StringComparison.OrdinalIgnoreCase, e3);

            v = new JValue("ORDINAL");
            d = v;
            StringComparison e4 = (StringComparison)d;
            Assert.AreEqual(StringComparison.Ordinal, e4);

            StringComparison e5 = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.Ordinal, e5);

            v = new JValue((int)StringComparison.OrdinalIgnoreCase);
            Assert.AreEqual(JTokenType.Integer, v.Type);
            StringComparison e6 = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.OrdinalIgnoreCase, e6);
        }
開發者ID:andersonb,項目名稱:Newtonsoft.Json,代碼行數:38,代碼來源:JValueTests.cs

示例6: EnumTests

        public void EnumTests()
        {
            JValue v = new JValue(StringComparison.Ordinal);
            Assert.AreEqual(JTokenType.Integer, v.Type);

            string s = v.ToString();
            Assert.AreEqual("Ordinal", s);

            StringComparison e = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.Ordinal, e);

            dynamic d = new JValue(StringComparison.CurrentCultureIgnoreCase);
            StringComparison e2 = (StringComparison)d;
            Assert.AreEqual(StringComparison.CurrentCultureIgnoreCase, e2);

            string s1 = d.ToString();
            Assert.AreEqual("CurrentCultureIgnoreCase", s1);

            string s2 = (string)d;
            Assert.AreEqual("CurrentCultureIgnoreCase", s2);

            d = new JValue("OrdinalIgnoreCase");
            StringComparison e3 = (StringComparison)d;
            Assert.AreEqual(StringComparison.OrdinalIgnoreCase, e3);

            v = new JValue("ORDINAL");
            d = v;
            StringComparison e4 = (StringComparison)d;
            Assert.AreEqual(StringComparison.Ordinal, e4);

            StringComparison e5 = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.Ordinal, e5);

            v = new JValue((int)StringComparison.OrdinalIgnoreCase);
            Assert.AreEqual(JTokenType.Integer, v.Type);
            StringComparison e6 = v.ToObject<StringComparison>();
            Assert.AreEqual(StringComparison.OrdinalIgnoreCase, e6);

            // does not support EnumMember. breaking change to add
            ExceptionAssert.Throws<ArgumentException>(() =>
            {
                d = new JValue("value_a");
                EnumA e7 = (EnumA)d;
                Assert.AreEqual(EnumA.ValueA, e7);
            }, "Requested value 'value_a' was not found.");
        }
開發者ID:ChuangYang,項目名稱:Newtonsoft.Json,代碼行數:46,代碼來源:JValueTests.cs

示例7: ToString

    public void ToString()
    {
      JValue v;

      v = new JValue(true);
      Assert.AreEqual("True", v.ToString());

      v = new JValue(Encoding.UTF8.GetBytes("Blah"));
      Assert.AreEqual("System.Byte[]", v.ToString(null, CultureInfo.InvariantCulture));

      v = new JValue("I am a string!");
      Assert.AreEqual("I am a string!", v.ToString());

      v = new JValue(null, JTokenType.Null);
      Assert.AreEqual("", v.ToString());

      v = new JValue(null, JTokenType.Null);
      Assert.AreEqual("", v.ToString(null, CultureInfo.InvariantCulture));

      v = new JValue(new DateTime(2000, 12, 12, 20, 59, 59, DateTimeKind.Utc), JTokenType.Date);
      Assert.AreEqual("12/12/2000 20:59:59", v.ToString(null, CultureInfo.InvariantCulture));
    }
開發者ID:nicklv,項目名稱:SharpOAuth2,代碼行數:22,代碼來源:JValueTests.cs

示例8: NumericCanRoundtrip

        /// <summary>
        /// Ensure that a numeric value can safely roundtrip as a double.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="desiredType">The desired type.</param>
        /// <returns>
        /// True if the value can roundtrip, false otherwise.
        /// </returns>
        private static bool NumericCanRoundtrip(object value, Type desiredType)
        {
            // Make sure that the value can roundtrip
            bool canRoundtrip = false;
            object original = Convert.ChangeType(value, desiredType, CultureInfo.InvariantCulture);
            double converted = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            try
            {
                JValue jv = new JValue(converted);
                string jvString = jv.ToString();
                JValue reverse = JValue.Parse(jvString) as JValue;

                if (reverse != null)
                {
                    object roundtripped = Convert.ChangeType(reverse.Value, desiredType, CultureInfo.InvariantCulture);
                    canRoundtrip = original.Equals(roundtripped);
                }
            }
            catch (InvalidCastException)
            {
            }
            catch (OverflowException)
            {
            }
            return canRoundtrip;
        }
開發者ID:TroyBolton,項目名稱:azure-mobile-services,代碼行數:34,代碼來源:JsonExtensions.cs

示例9: getAuthToken

		private string getAuthToken() {
			bool needNewToken = false;
			
			if (token == null || token.Equals("")) {
				needNewToken = true;	
				Log.Info("HockeyStreams - Need to login");
			} else if (tokenCreateDate == null || tokenCreateDate.AddHours(tokenResetDurationHours) > DateTime.Now) {
				// current token is more than 12 hours old
				needNewToken = true;
				Log.Info("HockeyStreams - Token has expired, need to login again");
			} 
			
			if (needNewToken) {
				string postData = string.Format("username={0}&password={1}&key={2}", username, password, apiKey);
			
				// get the authentication token
				String jsonResponse =  GetWebData(apiUrl_login,postData,null,null,null, false, false, useragent, null, null, false);
				
				JObject jsonLogin = JObject.Parse(jsonResponse);
				JToken authToken = new JValue("");
				bool yes = jsonLogin.TryGetValue("token",out authToken);
				token = authToken.ToString();
				tokenCreateDate = DateTime.Now;
			}
			
			return token;
			
			
		}
開發者ID:leesanghyun2,項目名稱:mp-onlinevideos2,代碼行數:29,代碼來源:HockeyStreams.cs

示例10: VisitValue

        JToken VisitValue(JValue jValue)
        {
            if (jValue.Type == JTokenType.Boolean)
            {
                sb.Append(jValue.ToString().ToLower());
            }
            else if (jValue.Type == JTokenType.String)
            {
                string s = (string)jValue.Value;
                bool needsQuotes =
                    (s.Length == 0 ||
                    s.IndexOfAny(new char[] { '"', '\\', '/', '\b', '\f', '\n', '\r', '\t', '#', ':', ',', '[', ']', '{', '}' }) != -1);

                // NOTE: The order is important here; \\ should get replaced last
                s = s
                    .Replace("\\", "\\\\")
                    .Replace("\"", "\\\"")
                    .Replace("/", "\\/")
                    .Replace("\b", "\\b")
                    .Replace("\f", "\\f")
                    .Replace("\n", "\\n")
                    .Replace("\r", "\\r")
                    .Replace("\t", "\\t");

                if (needsQuotes)
                {
                    sb.AppendFormat("\"{0}\"", s);
                }
                else
                {
                    sb.Append(s);
                }
            }
            else if (jValue.Type == JTokenType.Array || jValue.Type == JTokenType.Object)
            {
                Visit(jValue);
            }
            else
            {
                sb.Append(jValue.Value.ToString());
            }

            return jValue;
        }
開發者ID:jlyonsmith,項目名稱:Tson,代碼行數:44,代碼來源:TsonJTokenVisitor.cs


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