Beispiel #1
0
        private ParseState Parse_between()
        {
            while (this.pointer < str.Length)
            {
                char c = this.str[this.pointer];

                if (c == '[')
                {
                    ++this.pointer;
                    return(ParseState.List_start);
                }
                else if (c == ']')
                {
                    ++this.pointer;
                    return(ParseState.List_end);
                }
                else if (c == '{')
                {
                    ++this.pointer;
                    return(ParseState.Obj_begin);
                }
                else if (c == '}')
                {
                    ++this.pointer;
                    return(ParseState.Obj_end);
                }
                else if (c == '\"')
                {
                    ++this.pointer;
                    this.withQuote_flag = true;
                    return(ParseState.Value_str);
                }
                else if (JSON_helper.IsNum(c) || c == '-')
                {
                    this.withQuote_flag = false;
                    return(ParseState.Value_num);
                }
                else if (JSON_helper.IsLetter(c))
                {
                    this.withQuote_flag = false;
                    return(ParseState.Value_str);
                }
                else
                {
                    ++this.pointer;
                }
            }

            return(ParseState.None);
        }
Beispiel #2
0
        private ParseState Parse_value()
        {
            StringBuilder sb = new StringBuilder();

            while (this.pointer < str.Length)
            {
                char c = this.str[this.pointer];

                if (this.withQuote_flag)
                {
                    if (c == '\"')
                    {
                        ++this.pointer;
                        this.val_str = sb.ToString();
                        return(ParseState.Between);
                    }
                    else
                    {
                        sb.Append(c);
                        ++this.pointer;
                    }
                }
                else
                {
                    if (JSON_helper.IsLetter(c))
                    {
                        sb.Append(c);
                        ++this.pointer;
                    }
                    else
                    {
                        this.val_str = sb.ToString();
                        return(ParseState.Between);
                    }
                }
            }

            if (sb.Length > 0)
            {
                this.val_str = sb.ToString();
                return(ParseState.Obj_end);
            }

            return(ParseState.None);
        }