コード例 #1
0
        public void SetValue(JToken json)
        {
            switch (json.Type)
            {
            case JTokenType.Array:
                ValueType = VariantType.Map;
                foreach (var item in json)
                {
                    Add(Get(item));
                }
                break;

            case JTokenType.Object:
                ValueType = VariantType.Map;
                foreach (var property in (json as JObject).Properties())
                {
                    Add(property.Name, Get(property.Value));
                    if (property.Name.StartsWith(Defines.VAR_INDEX_VALUE))
                    {
                        IsArray     = true;
                        ArrayLength = Math.Max(ArrayLength, VariantMap.IndexStringToInt(property.Name) + 1);
                    }
                }
                break;

            case JTokenType.Boolean:
                ValueType = VariantType.Boolean;
                Value     = (bool)json;
                break;

            case JTokenType.Null:
                ValueType = VariantType.Null;
                break;

            case JTokenType.String:
                ValueType = VariantType.String;
                Value     = (string)json;
                break;

            case JTokenType.Integer:
                if ((ulong)json <= int.MaxValue)
                {
                    ValueType = VariantType.Int32;
                    Value     = (int)json;
                }
                else
                {
                    ValueType = VariantType.Int64;
                    Value     = (long)json;
                }
                break;

            case JTokenType.Float:
                ValueType = VariantType.Double;
                Value     = (double)json;
                break;

            case JTokenType.Undefined:
                ValueType = VariantType.Undefined;
                break;

            case JTokenType.Date:
                ValueType = VariantType.Date;
                Value     = (DateTime)json;
                break;

            case JTokenType.TimeSpan:
                ValueType = VariantType.Time;
                Value     = (DateTime)json;
                break;
            }
        }