Пример #1
0
        private Tuple <ParsedObject, int> GetJsonValue(string text, int currentPoint)
        {
            string jsonValue = "";
            string symbols   = ",[]{}";
            bool   quotationMarkWasClosed = true;

            while (!symbols.Contains(Convert.ToString(text[currentPoint])) || (symbols.Contains(Convert.ToString(text[currentPoint])) && !quotationMarkWasClosed))
            {
                if (text[currentPoint] == '\"')
                {
                    quotationMarkWasClosed ^= true;
                }
                jsonValue += text[currentPoint++];
            }
            if (text[currentPoint] == '{' || text[currentPoint] == '[')
            {
                Tuple <ParsedObject, int> nextItem = ParseJsonEntity(text, currentPoint);
                return(new Tuple <ParsedObject, int>(nextItem.Item1, nextItem.Item2 + 1));
            }
            ParsedObject response = new ParsedObject(ParsedObject.Type.SingleValue);

            response.SetValue(myTrim(jsonValue));
            return(new Tuple <ParsedObject, int>(response, currentPoint));
        }
Пример #2
0
        private ParsedObject Go()
        {
            ParsedObject newObject;

            if (!isNextSymbolIsBracket())
            {
                newObject = new ParsedObject(ParsedObject.Type.SingleValue);
                newObject.SetValue(ReadTillBracket());
                return(newObject);
            }

            newObject = new ParsedObject(ParsedObject.Type.NestedType);
            while (true)
            {
                string tag = ReadTag();
                newObject.AddSubObjectByKey(tag, Go());
                ReadTag(); // closing
                if (isNextTagIsClosing())
                {
                    break;
                }
            }
            return(newObject);
        }