Esempio n. 1
0
        public JsonObjectBase ReadNext()
        {
            if (EndOfDocument)
                return null;



            string name;

            if (_jsonSrc[CurrentPos] == '{')
            {
                var jsc = new JsonObjectClass
                {
                    Name = null,
                    Class = new JsonEngine("AnonymusClass[" + _objectName + "]", _jsonSrc, CurrentPos, '{', '}', _engines)
                };

                return jsc; 
            }

            if (_jsonSrc[CurrentPos] == '[')
                throw new Exception("Array can not be anonimus. Error in object "+_objectName);


            if (_jsonSrc[CurrentPos] == '"')
                name = ReadEndOfQuoting();
            else
            {
                _jsonObjectSimple.Name = null;
                _jsonObjectSimple.Value = ReadToEndWithourQuting();
                FindNextJsonItem();
                return _jsonObjectSimple;  
            }


            CurrentPos = FineNextNoSpace(CurrentPos);

            if (_jsonSrc[CurrentPos] == ',' || _jsonSrc[CurrentPos] == _closeTag)
            {

                _jsonObjectSimple.Value = name; 
                _jsonObjectSimple.Name = null;
                FindNextJsonItem();
                return _jsonObjectSimple;    
            }

            if (_jsonSrc[CurrentPos] != ':')
                throw new Exception("Error parsing json. Symbol [" + ':' + "] after [" + name + "]");


            CurrentPos = FineNextNoSpace(CurrentPos + 1);

            switch (_jsonSrc[CurrentPos])
            {
                case '"':
                    _jsonObjectSimple.Name = name;
                    _jsonObjectSimple.Value = ReadEndOfQuoting();
                    FindNextJsonItem();
                    return _jsonObjectSimple;

                case '{':
                    var jsc = new JsonObjectClass
                                  {
                                      Name = name,
                                      Class = new JsonEngine(name, _jsonSrc, CurrentPos, '{', '}', _engines)
                                  };

                    return jsc;

                case '[':
                    var jsa = new JsonArray
                    {
                        Name = name,
                        Array = new JsonEngine(name, _jsonSrc, CurrentPos,  '[', ']', _engines)
                    };

                    return jsa;


                default:

                    ReadToEndWithourQuting();

                    _jsonObjectSimple.Name = name;
                    _jsonObjectSimple.Value = null;
                    FindNextJsonItem();
                    return _jsonObjectSimple;

            }


        }
Esempio n. 2
0
        public JsonObjectBase ReadNext()
        {
            if (EndOfDocument)
            {
                return(null);
            }



            string name;

            if (_jsonSrc[CurrentPos] == '{')
            {
                var jsc = new JsonObjectClass
                {
                    Name  = null,
                    Class = new JsonEngine("AnonymusClass[" + _objectName + "]", _jsonSrc, CurrentPos, '{', '}', _engines)
                };

                return(jsc);
            }

            if (_jsonSrc[CurrentPos] == '[')
            {
                throw new Exception("Array can not be anonimus. Error in object " + _objectName);
            }


            if (_jsonSrc[CurrentPos] == '"')
            {
                name = ReadEndOfQuoting();
            }
            else
            {
                _jsonObjectSimple.Name  = null;
                _jsonObjectSimple.Value = ReadToEndWithourQuting();
                FindNextJsonItem();
                return(_jsonObjectSimple);
            }


            CurrentPos = FineNextNoSpace(CurrentPos);

            if (_jsonSrc[CurrentPos] == ',' || _jsonSrc[CurrentPos] == _closeTag)
            {
                _jsonObjectSimple.Value = name;
                _jsonObjectSimple.Name  = null;
                FindNextJsonItem();
                return(_jsonObjectSimple);
            }

            if (_jsonSrc[CurrentPos] != ':')
            {
                throw new Exception("Error parsing json. Symbol [" + ':' + "] after [" + name + "]");
            }


            CurrentPos = FineNextNoSpace(CurrentPos + 1);

            switch (_jsonSrc[CurrentPos])
            {
            case '"':
                _jsonObjectSimple.Name  = name;
                _jsonObjectSimple.Value = ReadEndOfQuoting();
                FindNextJsonItem();
                return(_jsonObjectSimple);

            case '{':
                var jsc = new JsonObjectClass
                {
                    Name  = name,
                    Class = new JsonEngine(name, _jsonSrc, CurrentPos, '{', '}', _engines)
                };

                return(jsc);

            case '[':
                var jsa = new JsonArray
                {
                    Name  = name,
                    Array = new JsonEngine(name, _jsonSrc, CurrentPos, '[', ']', _engines)
                };

                return(jsa);


            default:

                ReadToEndWithourQuting();

                _jsonObjectSimple.Name  = name;
                _jsonObjectSimple.Value = null;
                FindNextJsonItem();
                return(_jsonObjectSimple);
            }
        }