Ejemplo n.º 1
0
        internal new static JObject Parse(JsonStream jsonStream)
        {
            jsonStream.MoveToNextContent();
            if (!'{'.Equals(jsonStream.CurrentChar))
            {
                throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
            }
            List <KeyValuePair <string, JToken> > properties = new List <KeyValuePair <string, JToken> >();

            jsonStream.Move();
            jsonStream.MoveToNextContent();

            if (jsonStream.IsStartOfString())
            {
                while (true)
                {
                    var prop = GetNextProperty(jsonStream);
                    properties.Add(prop);

                    jsonStream.MoveToNextContent();
                    if (','.Equals(jsonStream.CurrentChar))
                    {
                        jsonStream.Move();
                        jsonStream.MoveToNextContent();
                        if (jsonStream.IsStartOfString())
                        {
                            continue;
                        }
                        else if ('}'.Equals(jsonStream.CurrentChar))
                        {
                            break;
                        }
                        else
                        {
                            throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                        }
                    }
                    else if ('}'.Equals(jsonStream.CurrentChar))
                    {
                        break;
                    }
                    else
                    {
                        throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                    }
                }
            }
            else if (!'}'.Equals(jsonStream.CurrentChar))
            {
                throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
            }

            jsonStream.Move();
            var answer = new JObject();

            answer.m_items = new Dictionary <string, JToken>(properties);
            return(answer);
        }
Ejemplo n.º 2
0
        internal new static JValue Parse(JsonStream jsonStream)
        {
            JValue answer;

            switch (jsonStream.CurrentChar)
            {
            case 'n':
                if (jsonStream.HasNullFollow())
                {
                    answer = new JValue(null);
                    jsonStream.MoveBehindNull();
                }
                else
                {
                    throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                }
                break;

            case 't':
                if (jsonStream.HasTrueFollow())
                {
                    answer = (JValue)true;
                    jsonStream.MoveBehindTrue();
                }
                else
                {
                    throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                }
                break;

            case 'f':
                if (jsonStream.HasFalseFollow())
                {
                    answer = (JValue)false;
                    jsonStream.MoveBehindFalse();
                }
                else
                {
                    throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                }
                break;

            default:
                if (jsonStream.IsStartOfString())
                {
                    var content = jsonStream.MoveBehindStringAndGet();
                    answer = (JValue)content;
                }
                else if (jsonStream.IsStartOfNumber())
                {
                    var number = jsonStream.MoveBehindNumberAndGet();
                    answer = (JValue)double.Parse(number);
                }
                else
                {
                    throw ExceptionHelpers.MakeJsonErrorException(jsonStream);
                }
                break;
            }
            return(answer);
        }