Пример #1
0
        private static ScannerData ScanObject(string json, int index)
        {
            var dict = new Dictionary <string, JSONObject>();

            var nextTokenIndex = SkipWhitespace(json, index + 1);

            if (json[nextTokenIndex] == ObjectEnd)
            {
                return(new ScannerData(JSONObject.CreateObject(dict), nextTokenIndex + 1));
            }

            while (json[index] != ObjectEnd)
            {
                index = SkipWhitespace(json, index + 1);
                if (json[index] != '"')
                {
                    throw new ParseError("Object keys must be strings", index);
                }
                string key;
                index = ScanBareString(json, index + 1, out key) + 1;
                index = SkipWhitespace(json, index);
                if (json[index] != ObjectSeparator)
                {
                    throw new ParseError("Expecting object separator (:)", index);
                }
                ++index;
                var valueResult = Scan(json, index);
                index = SkipWhitespace(json, valueResult.Index);
                if (json[index] != ObjectEnd && json[index] != ObjectPairSeparator)
                {
                    throw new ParseError("Expecting object pair separator (,) or object end (})", index);
                }
                dict[key] = valueResult.Result;
            }
            return(new ScannerData(JSONObject.CreateObject(dict), index + 1));
        }