示例#1
0
    private object ReadValue(JsonSerializer serializer, JsonReader reader)
    {
        while (reader.TokenType == JsonToken.Comment)
        {
            if (!reader.Read())
            {
                throw reader.CreateException("Unexpected end when reading ExpandoObject.");
            }
        }
        switch (reader.TokenType)
        {
        case JsonToken.StartObject:
            return(ReadObject(serializer, reader));

        case JsonToken.StartArray:
            return(ReadList(serializer, reader));

        default:
            if (JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
            {
                return(reader.Value);
            }
            throw reader.CreateException("Unexpected token when converting ExpandoObject");
        }
    }
        private object ReadValue(JsonReader reader)
        {
            while (reader.TokenType == JsonToken.Comment)
            {
                if (!reader.Read())
                {
                    throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
                }
            }

            switch (reader.TokenType)
            {
            case JsonToken.StartObject:
                return(ReadObject(reader));

            case JsonToken.StartArray:
                return(ReadList(reader));

            default:
                if (JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
                {
                    return(reader.Value);
                }

                throw JsonSerializationException.Create(reader, "Unexpected token when converting ExpandoObject: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
            }
        }
示例#3
0
        internal string ReadAsStringInternal()
        {
            _readType = ReadType.ReadAsString;

            JsonToken t;

            do
            {
                if (!ReadInternal())
                {
                    SetToken(JsonToken.None);
                    return(null);
                }
                else
                {
                    t = TokenType;
                }
            } while (t == JsonToken.Comment);

            if (t == JsonToken.String)
            {
                return((string)Value);
            }

            if (t == JsonToken.Null)
            {
                return(null);
            }

            if (JsonTokenUtils.IsPrimitiveToken(t))
            {
                if (Value != null)
                {
                    string s;
                    if (Value is IFormattable)
                    {
                        s = ((IFormattable)Value).ToString(null, Culture);
                    }
                    else
                    {
                        s = Value.ToString();
                    }

                    SetToken(JsonToken.String, s, false);
                    return(s);
                }
            }

            if (t == JsonToken.EndArray)
            {
                return(null);
            }

            throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t));
        }
示例#4
0
        public virtual string ReadAsString()
        {
            string    str;
            JsonToken contentToken = this.GetContentToken();

            if (contentToken <= JsonToken.String)
            {
                if (contentToken == JsonToken.None)
                {
                    return(null);
                }
                if (contentToken == JsonToken.String)
                {
                    return((string)this.Value);
                }
                goto Label0;
            }
            else if (contentToken != JsonToken.Null)
            {
                if (contentToken != JsonToken.EndArray)
                {
                    goto Label0;
                }
            }
            return(null);

Label0:
            if (JsonTokenUtils.IsPrimitiveToken(contentToken))
            {
                object value = this.Value;
                if (value != null)
                {
                    IFormattable formattable  = value as IFormattable;
                    IFormattable formattable1 = formattable;
                    if (formattable == null)
                    {
                        Uri uri  = value as Uri;
                        Uri uri1 = uri;
                        str = (uri != null ? uri1.OriginalString : value.ToString());
                    }
                    else
                    {
                        str = formattable1.ToString(null, this.Culture);
                    }
                    this.SetToken(JsonToken.String, str, false);
                    return(str);
                }
            }
            throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, contentToken));
        }
示例#5
0
        // Token: 0x06000C01 RID: 3073 RVA: 0x0004F300 File Offset: 0x0004D500
        public virtual string ReadAsString()
        {
            JsonToken contentToken = this.GetContentToken();

            if (contentToken <= JsonToken.String)
            {
                if (contentToken == JsonToken.None)
                {
                    goto IL_A1;
                }
                if (contentToken == JsonToken.String)
                {
                    return((string)this.Value);
                }
            }
            else
            {
                if (contentToken == JsonToken.Null)
                {
                    goto IL_A1;
                }
                if (contentToken == JsonToken.EndArray)
                {
                    goto IL_A1;
                }
            }
            if (JsonTokenUtils.IsPrimitiveToken(contentToken))
            {
                object value = this.Value;
                if (value != null)
                {
                    IFormattable formattable = value as IFormattable;
                    string       text;
                    if (formattable != null)
                    {
                        text = formattable.ToString(null, this.Culture);
                    }
                    else
                    {
                        Uri uri = value as Uri;
                        text = ((uri != null) ? uri.OriginalString : value.ToString());
                    }
                    this.SetToken(JsonToken.String, text, false);
                    return(text);
                }
            }
            throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, contentToken));
IL_A1:
            return(null);
        }
示例#6
0
        public virtual string ReadAsString()
        {
            string    str;
            JsonToken contentToken = this.GetContentToken();

            if (contentToken <= JsonToken.String)
            {
                if (contentToken == JsonToken.None)
                {
                    return(null);
                }
                if (contentToken == JsonToken.String)
                {
                    return((string)this.Value);
                }
                if (!JsonTokenUtils.IsPrimitiveToken(contentToken) || this.Value == null)
                {
                    throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, contentToken));
                }
                if (!(this.Value is IFormattable))
                {
                    str = (!(this.Value is Uri) ? this.Value.ToString() : ((Uri)this.Value).OriginalString);
                }
                else
                {
                    str = ((IFormattable)this.Value).ToString(null, this.Culture);
                }
                this.SetToken(JsonToken.String, str, false);
                return(str);
            }
            else if (contentToken != JsonToken.Null && contentToken != JsonToken.EndArray)
            {
                if (!JsonTokenUtils.IsPrimitiveToken(contentToken) || this.Value == null)
                {
                    throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, contentToken));
                }
                if (!(this.Value is IFormattable))
                {
                    str = (!(this.Value is Uri) ? this.Value.ToString() : ((Uri)this.Value).OriginalString);
                }
                else
                {
                    str = ((IFormattable)this.Value).ToString(null, this.Culture);
                }
                this.SetToken(JsonToken.String, str, false);
                return(str);
            }
            return(null);
        }
示例#7
0
        public virtual string ReadAsString()
        {
            string    originalString;
            JsonToken contentToken = this.GetContentToken();

            if (contentToken <= JsonToken.String)
            {
                switch (contentToken)
                {
                case JsonToken.None:
                    goto Label_0032;

                case JsonToken.String:
                    return((string)this.Value);
                }
                goto Label_0040;
            }
            if ((contentToken != JsonToken.Null) && (contentToken != JsonToken.EndArray))
            {
                goto Label_0040;
            }
            Label_0032:
            return(null);

Label_0040:
            if (!JsonTokenUtils.IsPrimitiveToken(contentToken) || (this.Value == null))
            {
                throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, contentToken));
            }
            if (this.Value is IFormattable)
            {
                originalString = ((IFormattable)this.Value).ToString(null, this.Culture);
            }
            else if (this.Value is Uri)
            {
                originalString = ((Uri)this.Value).OriginalString;
            }
            else
            {
                originalString = this.Value.ToString();
            }
            this.SetToken(JsonToken.String, originalString, false);
            return(originalString);
        }
        /// <summary>
        /// Reads the next JSON token from the stream as a <see cref="String"/>.
        /// </summary>
        /// <returns>A <see cref="String"/>. This method will return <c>null</c> at the end of an array.</returns>
        public virtual string ReadAsString()
        {
            JsonToken t = GetContentToken();

            switch (t)
            {
            case JsonToken.None:
            case JsonToken.Null:
            case JsonToken.EndArray:
                return(null);

            case JsonToken.String:
                return((string)Value);
            }

            if (JsonTokenUtils.IsPrimitiveToken(t))
            {
                if (Value != null)
                {
                    string s;
                    if (Value is IFormattable)
                    {
                        s = ((IFormattable)Value).ToString(null, Culture);
                    }
                    else if (Value is Uri)
                    {
                        s = ((Uri)Value).OriginalString;
                    }
                    else
                    {
                        s = Value.ToString();
                    }

                    SetToken(JsonToken.String, s, false);
                    return(s);
                }
            }

            throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t));
        }
示例#9
0
        private object ReadValue(JsonReader reader)
        {
            if (!reader.MoveToContent())
            {
                throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
            }
            JsonToken tokenType = reader.TokenType;

            if (tokenType == JsonToken.StartObject)
            {
                return(this.ReadObject(reader));
            }
            if (tokenType == JsonToken.StartArray)
            {
                return(this.ReadList(reader));
            }
            if (JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
            {
                return(reader.Value);
            }
            throw JsonSerializationException.Create(reader, "Unexpected token when converting ExpandoObject: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
        }
示例#10
0
    private object ReadValue(JsonReader reader, JsonSerializer serializer)
    {
        if (!reader.MoveToContent())
        {
            throw JsonSerializationExceptionHelper.Create(reader, "Unexpected end when reading ExpandoObject.");
        }
        switch (reader.TokenType)
        {
        case JsonToken.StartObject:
            return(ReadObject(reader, serializer));

        case JsonToken.StartArray:
            return(ReadList(reader, serializer));

        default:
            if (JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
            {
                return(reader.Value);
            }
            throw JsonSerializationExceptionHelper.Create(reader, string.Format("Unexpected token when converting ExpandoObject: {0}", reader.TokenType));
        }
    }
示例#11
0
        public virtual string ReadAsString()
        {
            JsonToken contentToken = this.GetContentToken();

            switch (contentToken)
            {
            case JsonToken.None:
            case JsonToken.Null:
            case JsonToken.EndArray:
                return((string)null);

            case JsonToken.String:
                return((string)this.Value);

            default:
                if (!JsonTokenUtils.IsPrimitiveToken(contentToken) || this.Value == null)
                {
                    throw JsonReaderException.Create(this,
                                                     "Error reading string. Unexpected token: {0}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                                                               (object)contentToken));
                }
                IFormattable formattable = this.Value as IFormattable;
                string       str;
                if (formattable != null)
                {
                    str = formattable.ToString((string)null, (IFormatProvider)this.Culture);
                }
                else
                {
                    Uri uri = this.Value as Uri;
                    str = uri != (Uri)null ? uri.OriginalString : this.Value.ToString();
                }

                this.SetToken(JsonToken.String, (object)str, false);
                return(str);
            }
        }
示例#12
0
        private Dictionary <string, string> ReadAttributeElements(JsonReader reader, XmlNamespaceManager manager)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            bool flag  = false;
            bool flag2 = false;

            if ((((reader.TokenType != JsonToken.String) && (reader.TokenType != JsonToken.Null)) && ((reader.TokenType != JsonToken.Boolean) && (reader.TokenType != JsonToken.Integer))) && (((reader.TokenType != JsonToken.Float) && (reader.TokenType != JsonToken.Date)) && (reader.TokenType != JsonToken.StartConstructor)))
            {
                while ((!flag && !flag2) && reader.Read())
                {
                    string    str2;
                    JsonToken tokenType = reader.TokenType;
                    if (tokenType != JsonToken.PropertyName)
                    {
                        if (tokenType != JsonToken.Comment)
                        {
                            if (tokenType != JsonToken.EndObject)
                            {
                                throw JsonSerializationException.Create(reader, "Unexpected JsonToken: " + reader.TokenType);
                            }
                            goto Label_0279;
                        }
                        goto Label_0280;
                    }
                    string str = reader.Value.ToString();
                    if (string.IsNullOrEmpty(str))
                    {
                        goto Label_0272;
                    }
                    char ch = str[0];
                    if (ch != '$')
                    {
                        if (ch != '@')
                        {
                            goto Label_026B;
                        }
                        str = str.Substring(1);
                        reader.Read();
                        str2 = this.ConvertTokenToXmlValue(reader);
                        dictionary.Add(str, str2);
                        if (this.IsNamespaceAttribute(str, out string str3))
                        {
                            manager.AddNamespace(str3, str2);
                        }
                    }
                    else if (((str == "$values") || (str == "$id")) || (((str == "$ref") || (str == "$type")) || (str == "$value")))
                    {
                        string prefix = manager.LookupPrefix("http://james.newtonking.com/projects/json");
                        if (prefix == null)
                        {
                            int?nullable = null;
                            while (manager.LookupNamespace("json" + nullable) != null)
                            {
                                nullable = new int?(nullable.GetValueOrDefault() + 1);
                            }
                            prefix = "json" + nullable;
                            dictionary.Add("xmlns:" + prefix, "http://james.newtonking.com/projects/json");
                            manager.AddNamespace(prefix, "http://james.newtonking.com/projects/json");
                        }
                        if (str == "$values")
                        {
                            flag = true;
                        }
                        else
                        {
                            str = str.Substring(1);
                            reader.Read();
                            if (!JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
                            {
                                throw JsonSerializationException.Create(reader, "Unexpected JsonToken: " + reader.TokenType);
                            }
                            str2 = reader.Value?.ToString();
                            dictionary.Add(prefix + ":" + str, str2);
                        }
                    }
                    else
                    {
                        flag = true;
                    }
                    continue;
Label_026B:
                    flag = true;
                    continue;
Label_0272:
                    flag = true;
                    continue;
Label_0279:
                    flag2 = true;
                    continue;
Label_0280:
                    flag2 = true;
                }
            }
            return(dictionary);
        }
示例#13
0
        private Dictionary <string, string> ReadAttributeElements(
            JsonReader reader,
            XmlNamespaceManager manager)
        {
            switch (reader.TokenType)
            {
            case JsonToken.StartConstructor:
            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.String:
            case JsonToken.Boolean:
            case JsonToken.Null:
            case JsonToken.Date:
                return((Dictionary <string, string>)null);

            default:
                Dictionary <string, string> dictionary = (Dictionary <string, string>)null;
                bool flag = false;
                while (!flag && reader.Read())
                {
                    switch (reader.TokenType)
                    {
                    case JsonToken.PropertyName:
                        string str1 = reader.Value.ToString();
                        if (!string.IsNullOrEmpty(str1))
                        {
                            switch (str1[0])
                            {
                            case '$':
                                if (str1 == "$values" || str1 == "$id" || (str1 == "$ref" || str1 == "$type") ||
                                    str1 == "$value")
                                {
                                    string prefix = manager.LookupPrefix("http://james.newtonking.com/projects/json");
                                    if (prefix == null)
                                    {
                                        if (dictionary == null)
                                        {
                                            dictionary = new Dictionary <string, string>();
                                        }
                                        int?nullable = new int?();
                                        while (manager.LookupNamespace("json" + (object)nullable) != null)
                                        {
                                            nullable = new int?(nullable.GetValueOrDefault() + 1);
                                        }
                                        prefix = "json" + (object)nullable;
                                        dictionary.Add("xmlns:" + prefix, "http://james.newtonking.com/projects/json");
                                        manager.AddNamespace(prefix, "http://james.newtonking.com/projects/json");
                                    }

                                    if (str1 == "$values")
                                    {
                                        flag = true;
                                        continue;
                                    }

                                    string str2 = str1.Substring(1);
                                    reader.Read();
                                    if (!JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
                                    {
                                        throw JsonSerializationException.Create(reader,
                                                                                "Unexpected JsonToken: " + (object)reader.TokenType);
                                    }
                                    if (dictionary == null)
                                    {
                                        dictionary = new Dictionary <string, string>();
                                    }
                                    string str3 = reader.Value?.ToString();
                                    dictionary.Add(prefix + ":" + str2, str3);
                                    continue;
                                }

                                flag = true;
                                continue;

                            case '@':
                                if (dictionary == null)
                                {
                                    dictionary = new Dictionary <string, string>();
                                }
                                string str4 = str1.Substring(1);
                                reader.Read();
                                string xmlValue = this.ConvertTokenToXmlValue(reader);
                                dictionary.Add(str4, xmlValue);
                                string prefix1;
                                if (this.IsNamespaceAttribute(str4, out prefix1))
                                {
                                    manager.AddNamespace(prefix1, xmlValue);
                                    continue;
                                }

                                continue;

                            default:
                                flag = true;
                                continue;
                            }
                        }
                        else
                        {
                            flag = true;
                            continue;
                        }

                    case JsonToken.Comment:
                    case JsonToken.EndObject:
                        flag = true;
                        continue;

                    default:
                        throw JsonSerializationException.Create(reader, "Unexpected JsonToken: " + (object)reader.TokenType);
                    }
                }

                return(dictionary);
            }
        }
示例#14
0
        ReadAsSmallDec()
        {
            JsonToken t = GetContentToken();

#if (JSON_SmallDecSupport)
            switch (t)
            {
            case JsonToken.None:
            case JsonToken.Null:
            case JsonToken.EndArray:
                return(SmallDec.NaN);

            case JsonToken.String:
                return(Value.ToString());

            case JsonToken.SmallDec:
                if (Value.GetType() == typeof(SmallDec))
                {
                    return((SmallDec)Value);
                }
                else
                {
                    dynamic changedObj = Convert.ChangeType(Value, Value.GetType(), CultureInfo.CurrentCulture);
                    return((SmallDec)changedObj);
                }

            case JsonToken.Integer:
                return((long)Value);

            case JsonToken.Float:
                return((decimal)Value);

            case JsonToken.Boolean:
                return((SmallDec)(bool)Value);
            }
#else
            Type SmallDecType = Type.GetType("SmallDec", true);
            //dynamic changedObj = Convert.ChangeType(Value, SmallDecType);
            switch (t)
            {
            case JsonToken.None:
            case JsonToken.Null:
            case JsonToken.EndArray:
                dynamic changedObj = Convert.ChangeType(Value, SmallDecType);
                return(changedObj.NaN);

            case JsonToken.String:
                return(Convert.ChangeType(ToString));

            case JsonToken.SmallDec:
                return(Convert.ChangeType(Value, SmallDecType));
            }
#endif
            if (JsonTokenUtils.IsPrimitiveToken(t))
            {
                if (Value != null)
                {
                    string       s;
                    IFormattable formattable = Value as IFormattable;
                    if (formattable != null)
                    {
                        s = formattable.ToString(null, Culture);
                    }
                    else
                    {
                        Uri uri = Value as Uri;
                        s = uri != null ? uri.OriginalString : Value.ToString();
                    }

                    SetToken(JsonToken.SmallDec, (SmallDec)s, false);
                    return(s);
                }
            }
            throw JsonReaderException.Create(this, "Error reading SmallDec. Unexpected token: {0}.".ToString());
        }
        private Dictionary <string, string> ReadAttributeElements(JsonReader reader, XmlNamespaceManager manager)
        {
            string xmlValue;
            string str;
            string str1;
            Dictionary <string, string> strs = new Dictionary <string, string>();
            bool flag  = false;
            bool flag1 = false;

            if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Null && reader.TokenType != JsonToken.Boolean && reader.TokenType != JsonToken.Integer && reader.TokenType != JsonToken.Float && reader.TokenType != JsonToken.Date && reader.TokenType != JsonToken.StartConstructor)
            {
                while (!flag && !flag1 && reader.Read())
                {
                    JsonToken tokenType = reader.TokenType;
                    if (tokenType == JsonToken.PropertyName)
                    {
                        string str2 = reader.Value.ToString();
                        if (string.IsNullOrEmpty(str2))
                        {
                            flag = true;
                        }
                        else
                        {
                            char chr = str2[0];
                            if (chr != '$')
                            {
                                if (chr != '@')
                                {
                                    flag = true;
                                }
                                else
                                {
                                    str2 = str2.Substring(1);
                                    reader.Read();
                                    xmlValue = this.ConvertTokenToXmlValue(reader);
                                    strs.Add(str2, xmlValue);
                                    if (!this.IsNamespaceAttribute(str2, out str))
                                    {
                                        continue;
                                    }
                                    manager.AddNamespace(str, xmlValue);
                                }
                            }
                            else if (str2 == "$values" || str2 == "$id" || str2 == "$ref" || str2 == "$type" || str2 == "$value")
                            {
                                string str3 = manager.LookupPrefix("http://james.newtonking.com/projects/json");
                                if (str3 == null)
                                {
                                    int?nullable = null;
                                    while (manager.LookupNamespace(string.Concat("json", nullable)) != null)
                                    {
                                        nullable = new int?(nullable.GetValueOrDefault() + 1);
                                    }
                                    str3 = string.Concat("json", nullable);
                                    strs.Add(string.Concat("xmlns:", str3), "http://james.newtonking.com/projects/json");
                                    manager.AddNamespace(str3, "http://james.newtonking.com/projects/json");
                                }
                                if (str2 != "$values")
                                {
                                    str2 = str2.Substring(1);
                                    reader.Read();
                                    if (!JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
                                    {
                                        throw JsonSerializationException.Create(reader, string.Concat("Unexpected JsonToken: ", reader.TokenType));
                                    }
                                    if (reader.Value != null)
                                    {
                                        str1 = reader.Value.ToString();
                                    }
                                    else
                                    {
                                        str1 = null;
                                    }
                                    xmlValue = str1;
                                    strs.Add(string.Concat(str3, ":", str2), xmlValue);
                                }
                                else
                                {
                                    flag = true;
                                }
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                    }
                    else if (tokenType == JsonToken.Comment)
                    {
                        flag1 = true;
                    }
                    else
                    {
                        if (tokenType != JsonToken.EndObject)
                        {
                            throw JsonSerializationException.Create(reader, string.Concat("Unexpected JsonToken: ", reader.TokenType));
                        }
                        flag1 = true;
                    }
                }
            }
            return(strs);
        }