예제 #1
0
        private int ParseMap(int offset)
        {
            int offsetStart = offset;

            nodeType = JsonType.map;
            map      = new Dictionary <string, JSON>();

            offset += SkipWhiteSpace(offset);

            //  Start of map
            if (source[offset] != '{')
            {
                throw new Exception("Invalid Map");
            }
            offset += 1;

            while (true)
            {
                offset += SkipWhiteSpace(offset);
                if (source[offset] == '}')
                {
                    break;
                }

                JSON key = new JSON();
                offset += key.Parse(source, offset);
                if (key.nodeType != JsonType.text)
                {
                    throw new Exception("Invalid map");
                }

                offset += SkipWhiteSpace(offset);

                if (source[offset] != ':')
                {
                    throw new Exception("Invalid Map");
                }
                offset += 1;

                JSON value = new JSON();
                offset += value.Parse(source, offset);

                offset += SkipWhiteSpace(offset);

                map[key.text] = value;

                if (source[offset] != ',')
                {
                    break;
                }
                offset += 1;
            }


            //  End of map
            if (source[offset] != '}')
            {
                throw new Exception("Invalid Map");
            }
            offset += 1;

            offset += SkipWhiteSpace(offset);

            return(offset - offsetStart);
        }