コード例 #1
0
        public static IEnumerable <string> EnumeratePropertyNames(this JsValue val)
        {
            var lenId = JsPropertyId.FromString("length");
            var names = val.GetOwnPropertyNames();
            var len   = names.GetProperty(lenId).ToInt32();

            for (var i = 0; i < len; i++)
            {
                yield return(names.GetIndexedProperty(JsValue.FromInt(i)).ToString());
            }
        }
コード例 #2
0
        private JToken VisitObject(JsValue value)
        {
            var jsonObject = new JObject();
            var properties = Visit(value.GetOwnPropertyNames()).ToObject <string[]>();

            foreach (var property in properties)
            {
                var propertyId    = JsPropertyId.FromString(property);
                var propertyValue = value.GetProperty(propertyId);
                jsonObject.Add(property, Visit(propertyValue));
            }

            return(jsonObject);
        }
コード例 #3
0
        /// <summary>
        /// added by chuan.yin in 2017/4/27
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private object MapToNetObject(JsValue value)
        {
            if (value.ValueType == JsValueType.Object)
            {
                var descstr = value.ConvertToString().ToString();
                if (descstr == "[object Object]")
                {
                    //json对象
                    var result = new Dictionary <string, object>();
                    var names  = value.GetOwnPropertyNames();
                    if (names.ValueType == JsValueType.String)
                    {
                        result.Add(names.ToString(), ConvertJsObjectToNetObject(value.GetProperty(names.ToString())));
                    }
                    else if (names.ValueType == JsValueType.Array)
                    {
                        var arrIndex = ToArray(names);
                        foreach (var key in arrIndex)
                        {
                            result.Add(key.ToString(), ConvertJsObjectToNetObject(value.GetProperty(key.ToString())));
                        }
                    }

                    return(result);
                }
                else if (descstr.ToLower().Contains("gmt"))
                {
                    var    result      = DateTime.MinValue;
                    string format      = "ddd MMM dd yyyy HH:mm:ss 'GMT'K";
                    bool   validFormat = DateTime.TryParseExact(descstr.Split('(')[0].Trim(), format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result);
                    if (validFormat)
                    {
                        return(result);
                    }
                    else
                    {
                        return(descstr);
                    }
                }
                else
                {
                    return(value);
                }
            }
            else
            {
                return(value);
            }
        }
コード例 #4
0
 public static IEnumerable <KeyValuePair <string, JsValue> > EnumerateProperties(this JsValue _this)
 => from nameVal in EnumerateArrayValues(_this.GetOwnPropertyNames())
 let name = nameVal.ToString()
            let propId                     = JsPropertyId.FromString(name)
                                   let val = _this.GetProperty(propId)
                                             select new KeyValuePair <string, JsValue>(name, val);