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


C# Linq.JValue類代碼示例

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


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

示例1: Transform

 public static IExpressionConstant Transform(JValue obj)
 {
     // TODO: make this do something
     //var val = obj.Value;
     if (obj.Type.Equals(JTokenType.Integer)) 
     {
         return NumericValue.Create(obj.ToObject<int>());
     } 
     else if (obj.Type.Equals(JTokenType.Float))
     {
         return NumericValue.Create(obj.ToObject<decimal>());
     }
     else if (obj.Type.Equals(JTokenType.String))
     {
         return new StringValue(obj.ToObject<String>());
     }
     else if (obj.Type.Equals(JTokenType.Boolean))
     {
         return new BooleanValue(obj.ToObject<bool>());
     }
     else if (obj.Type.Equals(JTokenType.Null))
     {
         //throw new ApplicationException("NULL Not implemented yet");
         return null; // TODO: Change this to an option
     }
     else
     {
         throw new Exception("Don't know how to transform a " +obj.GetType()+ ".");
     }
 }
開發者ID:gitter-badger,項目名稱:Liquid.NET,代碼行數:30,代碼來源:DictionaryFactory.cs

示例2: ConvertPesudoTypes

        public static JToken ConvertPesudoTypes(JToken data, FormatOptions fmt)
        {
            var reqlTypes = data.SelectTokens("$..$reql_type$").ToList();

            foreach ( var typeToken in reqlTypes )
            {
                var reqlType = typeToken.Value<string>();
                //JObject -> JProerty -> JVaule:$reql_type$, go backup the chain.
                var pesudoObject = typeToken.Parent.Parent as JObject;

                JToken convertedValue = null;
                if( reqlType == Time )
                {
                    if( fmt.RawTime )
                        continue;
                    convertedValue = new JValue(GetTime(pesudoObject));
                }
                else if( reqlType == GroupedData )
                {
                    if( fmt.RawGroups )
                        continue;
                    convertedValue = new JValue(GetGrouped(pesudoObject));
                }
                else if( reqlType == Binary )
                {
                    if( fmt.RawBinary )
                        continue;
                    convertedValue = new JArray(GetBinary(pesudoObject));
                }

                pesudoObject.Replace(convertedValue);
            }

            return data;
        }
開發者ID:cadabloom,項目名稱:RethinkDb.Driver,代碼行數:35,代碼來源:Converter3.cs

示例3: FromObjectTimeSpan

 public void FromObjectTimeSpan()
 {
     var token1 = new JValue(TimeSpan.FromDays(1));
     var token2 = JToken.FromObject(token1);
     Assert.IsTrue(JToken.DeepEquals(token1, token2));
     Assert.AreEqual(token1.Type, token2.Type);
 }
開發者ID:rlugojr,項目名稱:Newtonsoft.Json,代碼行數:7,代碼來源:LinqToJsonTest.cs

示例4: Process

        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(FormBuilderContext context)
        {
            if (context.Property.GetCustomAttribute<FormDisplayAttribute>() != null)
            {
                FormDisplayAttribute formDisplayAttribute = context.Property.GetCustomAttribute<FormDisplayAttribute>();

                // Build a new hierarchy object for the element
                JObject hierachyObject = new JObject();
                JArray hierarcyItems = new JArray();

                hierachyObject["type"] = new JValue("section");
                hierachyObject["items"] = hierarcyItems;
                
                if (context.CurrentFormElement != null)
                {
                    // Move the current element into the form hierarcy
                    hierarcyItems.Add(context.CurrentFormElement);
                    context.CurrentFormElementParent.Remove(context.CurrentFormElement);
                    context.CurrentFormElementParent.Add(hierachyObject);
                }

                // Set the new parent element to the current hierarchy
                context.CurrentFormElementParent = hierarcyItems;

                string cssClasses = ConvertDisplayWidthToCssClass(formDisplayAttribute.DisplayWidth);

                if (!string.IsNullOrEmpty(cssClasses))
                {
                    hierachyObject["htmlClass"] = new JValue(cssClasses);
                }
            }
        }
開發者ID:fancyDevelopment,項目名稱:Fancy.SchemaFormBuilder,代碼行數:36,代碼來源:DisplayFormModule.cs

示例5: LabelToTrafficLight

 private string LabelToTrafficLight(JValue value)
 {
     if ((double) value > 0 && (double) value < 60) return "green";
     if ((double)value >= 60 && (double)value < 200) return "yellow";
     if ((double)value >= 200) return "red";
     return null;
 }
開發者ID:ChargedSynapse,項目名稱:buyaway,代碼行數:7,代碼來源:MachineLearningController.cs

示例6: FromObjectUri

 public void FromObjectUri()
 {
     var token1 = new JValue(new Uri("http://www.newtonsoft.com"));
     var token2 = JToken.FromObject(token1);
     Assert.IsTrue(JToken.DeepEquals(token1, token2));
     Assert.AreEqual(token1.Type, token2.Type);
 }
開發者ID:rlugojr,項目名稱:Newtonsoft.Json,代碼行數:7,代碼來源:LinqToJsonTest.cs

示例7: ToJsonObject

        public object ToJsonObject()
        {
            var content = new JObject(new JProperty(NAME, new JObject()));

            if (_boost == null && _minSimilarity == null && _prefixLength == null)
            {
                content[NAME][_name] = new JValue(_value);
            }
            else
            {
                content[NAME][_name] = new JObject();
                content[NAME][_name]["value"] = new JValue(_value);

                if (_boost != null)
                {
                    content[NAME][_name]["boost"] = _boost;
                }

                if (_minSimilarity != null)
                {
                    content[NAME][_name]["min_similarity"] = _minSimilarity;
                }

                if (_prefixLength != null)
                {
                    content[NAME][_name]["prefix_length"] = _prefixLength;
                }
            }

            return content;
        }
開發者ID:stephenpope,項目名稱:Rubber,代碼行數:31,代碼來源:FuzzyQueryBuilder.cs

示例8: FromObjectGuid

 public void FromObjectGuid()
 {
     var token1 = new JValue(Guid.NewGuid());
     var token2 = JToken.FromObject(token1);
     Assert.IsTrue(JToken.DeepEquals(token1, token2));
     Assert.AreEqual(token1.Type, token2.Type);
 }
開發者ID:rlugojr,項目名稱:Newtonsoft.Json,代碼行數:7,代碼來源:LinqToJsonTest.cs

示例9: ChangeValue

    public void ChangeValue()
    {
      JValue v = new JValue(true);
      Assert.AreEqual(true, v.Value);
      Assert.AreEqual(JTokenType.Boolean, v.Type);

      v.Value = "Pie";
      Assert.AreEqual("Pie", v.Value);
      Assert.AreEqual(JTokenType.String, v.Type);

      v.Value = null;
      Assert.AreEqual(null, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);

      v.Value = (int?)null;
      Assert.AreEqual(null, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);

      v.Value = "Pie";
      Assert.AreEqual("Pie", v.Value);
      Assert.AreEqual(JTokenType.String, v.Type);

      v.Value = DBNull.Value;
      Assert.AreEqual(DBNull.Value, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);

      byte[] data = new byte[0];
      v.Value = data;

      Assert.AreEqual(data, v.Value);
      Assert.AreEqual(JTokenType.Bytes, v.Type);
    }
開發者ID:thirumg,項目名稱:Avro.NET,代碼行數:32,代碼來源:JValueTests.cs

示例10: ToJsonObject

        public object ToJsonObject()
        {
            var content = new JObject();
            content[_fieldName] = new JObject();

            if (_order != SortOrder.ASC)
            {
                content[_fieldName]["order"] = "desc";
            }

            if (_missing != null)
            {
                content[_fieldName]["missing"] = new JValue(_missing);
            }

            if (_ignoreUnampped != null)
            {
                content[_fieldName]["ignore_unmapped"] = _ignoreUnampped;
            }

            if (_nestedFilter != null)
            {
              content[_fieldName]["nested_filter"] = _nestedFilter.ToJsonObject() as JObject;
            }

            return content;
        }
開發者ID:ngnono,項目名稱:NEST,代碼行數:27,代碼來源:FieldSortBuilder.cs

示例11: Process

        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(FormBuilderContext context)
        {
            // Get all help attributes
            List<FormHelpAttribute> helps = context.Property.GetCustomAttributes<FormHelpAttribute>().ToList();

            // If the current property has no helps this module has nothing to to
            if (!helps.Any())
            {
                return;
            }

            foreach (FormHelpAttribute help in helps)
            {
                string helpCssClases = DetermineHelpCssClasses(help.HelpType);

                string helpText = GetTextForKey(help.HelpText, context);

                // Create the help JSON object
                JObject helpObject = new JObject();
                helpObject["type"] = new JValue("help");
                helpObject["helpvalue"] = new JValue("<div class=\"" + helpCssClases + "\" >" + helpText + "</div>");

                if (!string.IsNullOrEmpty(help.Condition))
                {
                    helpObject["condition"] = ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, help.Condition);
                }

                context.CurrentFormElementParent.Add(helpObject);
            }
        }
開發者ID:fancyDevelopment,項目名稱:Fancy.SchemaFormBuilder,代碼行數:34,代碼來源:HelpFormModule.cs

示例12: Example

        public void Example()
        {
            #region Usage
            JValue s1 = new JValue("A string");
            JValue s2 = new JValue("A string");
            JValue s3 = new JValue("A STRING");

            Console.WriteLine(JToken.DeepEquals(s1, s2));
            // true

            Console.WriteLine(JToken.DeepEquals(s2, s3));
            // false

            JObject o1 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

            JObject o2 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

            Console.WriteLine(JToken.DeepEquals(o1, o2));
            // true

            Console.WriteLine(JToken.DeepEquals(s1, o1["String"]));
            // true
            #endregion
        }
開發者ID:Redth,項目名稱:Newtonsoft.Json,代碼行數:34,代碼來源:DeepEquals.cs

示例13: Process

        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(FormBuilderContext context)
        {
            FormArrayAttribute arrayAttribute = context.Property.GetCustomAttribute<FormArrayAttribute>();
                
            // Test to the form subobject attribute
            if (arrayAttribute != null)
            {
                if (context.Property.PropertyType.GetInterfaces()
                    .Where(i => i.GetTypeInfo().IsGenericType)
                    .Select(i => i.GetGenericTypeDefinition()).Any(i => i == typeof (IEnumerable<>)))
                {
                    // Get the subtype from a generic type argument
                    Type subType = context.Property.PropertyType.GetGenericArguments()[0];

                    // Create the subform
                    JContainer properties = context.FormBuilder.BuildForm(subType, context.OriginDtoType, context.TargetCulture, context.FullPropertyPath + "[]");

                    // Merge the properties of the sub object into the current context
                    JObject currentFormElement = context.GetOrCreateCurrentFormElement();
                    currentFormElement["key"] = context.FullPropertyPath;
                    currentFormElement["items"] = properties;

                    if (!string.IsNullOrEmpty(arrayAttribute.AddButtonTitle))
                    {
                        string addText = GetTextForKey(arrayAttribute.AddButtonTitle, context);
                        currentFormElement["add"] = new JValue(addText);
                    }
                }
                else
                {
                    throw new InvalidOperationException("An FormArrayAttribute must always be on a property with a type derived from IEnumerable<>");
                }
            }
        }
開發者ID:PragmaticIT,項目名稱:Fancy.SchemaFormBuilder,代碼行數:38,代碼來源:ArrayFormModule.cs

示例14: FirebasePriority

        internal FirebasePriority(JValue priority)
        {
            if (priority == null || priority.Type == JTokenType.Null)
            {
                Type = PriorityType.None;
                return;
            }

            switch (priority.Type)
            {
                case JTokenType.None:
                    Type = PriorityType.None;
                    return;
                case JTokenType.Integer:
                case JTokenType.Float:
                    Type = PriorityType.Numeric;
                    _fp = priority.Value<float>();
                    return;
                case JTokenType.String:
                    int value;
                    if (int.TryParse(priority.Value<string>(), out value))
                    {
                        Type = PriorityType.Numeric;
                        _fp = value;
                    }
                    else
                    {
                        Type = PriorityType.String;
                        _sp = priority.Value<string>();
                    }
                    return;
                default:
                    throw new Exception(string.Format("Unable to load priority of type: {0}", priority.Type));
            }
        }
開發者ID:Dev01FC,項目名稱:CnC-SC,代碼行數:35,代碼來源:FirebasePriority.cs

示例15: Enquote

        ///// <summary>
        ///// Produce a string in double quotes with backslash sequences in all the right places.
        ///// 
        ///// 常用的用法:String.Format("{0}.setValue({1});", ClientJavascriptID, JsHelper.Enquote(Text))
        ///// 大部分情況下,可以使用 GetJsString 函數代替此函數
        ///// 此函數返回的是雙引號括起來的字符串,用來作為JSON屬性比較合適,一般用在OnAjaxPreRender
        ///// 但是作為HTML屬性時,由於HTML屬性本身就是雙引號括起來的,就容易引起衝突
        ///// 
        ///// </summary>
        ///// <param name="s">A String</param>
        ///// <returns>A String correctly formatted for insertion in a JSON message.</returns>
        /// <summary>
        /// 返回的是雙引號括起來的字符串,用來作為JSON屬性比較合適
        /// </summary>
        /// <param name="s">源字符串</param>
        /// <returns>雙引號括起來的字符串</returns>
        public static string Enquote(string s)
        {
            string jsonString = new JValue(s).ToString(Formatting.None);

            // The browser HTML parser will see the </script> within the string and it will interpret it as the end of the script element.
            // http://www.xiaoxiaozi.com/2010/02/24/1708/
            // http://stackoverflow.com/questions/1659749/script-tag-in-javascript-string
            jsonString = jsonString.Replace("</script>", @"<\/script>");

            return jsonString;
            /*
            if (s == null || s.Length == 0)
            {
                return "\"\"";
            }
            char c;
            int i;
            int len = s.Length;
            StringBuilder sb = new StringBuilder(len + 4);
            string t;

            sb.Append('"');
            for (i = 0; i < len; i += 1)
            {
                c = s[i];
                if ((c == '\\') || (c == '"') || (c == '>'))
                {
                    sb.Append('\\');
                    sb.Append(c);
                }
                else if (c == '\b')
                    sb.Append("\\b");
                else if (c == '\t')
                    sb.Append("\\t");
                else if (c == '\n')
                    sb.Append("\\n");
                else if (c == '\f')
                    sb.Append("\\f");
                else if (c == '\r')
                    sb.Append("\\r");
                else
                {
                    if (c < ' ')
                    {
                        //t = "000" + Integer.toHexString(c);
                        string tmp = new string(c, 1);
                        t = "000" + int.Parse(tmp, System.Globalization.NumberStyles.HexNumber);
                        sb.Append("\\u" + t.Substring(t.Length - 4));
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
            }
            sb.Append('"');
            return sb.ToString();
             * */
        }
開發者ID:GitHubXur,項目名稱:Fine-UI,代碼行數:75,代碼來源:JsHelper.cs


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