Esempio n. 1
0
 public TemplateMark()
 {
     json = new JSON();
     json["name"] = new QuoteString(null, '\'');
     json["sql"] = new QuoteString(null, '\'');
     json["xsl"] = new QuoteString(null, '\'');
     json["node"] = new QuoteString("div", '\'');
     json["params"] = new JSON();
 }
Esempio n. 2
0
        /// <summary>
        /// 读数组对象
        /// </summary>
        /// <param name="type">输出结束字符</param>
        /// <returns>返回无类型数组</returns>
        public object[] ReadArray(out int type)
        {
            if (Current != '[') throw new Exception("should be '['");

            List<object> list = new List<object>();

            int ch;

            ARRAY_LOOP_READ:

            ReadBlank();

            ch = Read();
            if (ch < 0 || ch == '}' || ch == ',')
            {
                type = ch;
                return list.ToArray();
            }
            string _value;

            switch (ch)
            {
                case '\'':
                case '"':
                    ReadQuote(ch, out _value);
                    list.Add(ConvertData(_value, ch));
                    Read();
                    ReadBlank();

                    switch (Current)
                    {
                        case ']':
                            ReadBlank();
                            type = Read();
                            return list.ToArray();
                        case ',':
                            ReadBlank();
                            goto ARRAY_LOOP_READ;
                        default:
                            throw new Exception("Why?!");
                    }
                case '{':
                    JSON json = new JSON();
                    ReadToJSON(this, json, out type);
                    list.Add(json);
                    goto ARRAY_LOOP_READ;
                case '[':
                    object[] arr = ReadArray(out type);
                    list.Add(arr);
                    goto ARRAY_LOOP_READ;
                default:
                    ReadTo(out _value, ',', ']');
                    list.Add(ConvertData(_value, -1));
                    ReadBlank();
                    switch (Current)
                    {
                        case ']':
                            type = Read();
                            return list.ToArray();
                        case ',':
                            goto ARRAY_LOOP_READ;
                        default:
                            throw new Exception("Why?!");
                    }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 读取属性值
        /// </summary>
        /// <param name="value">输出属性值</param>
        /// <param name="endtype">根据结束字符,判断为结束对象或者进入下一属性)</param>
        public void ReadPorperty(out object value, out int endtype)
        {
            if (Current != ':') throw new Exception("The current char should be ':'");
            ReadBlank();

            int ch = Read();
            int start = position - 1;
            int sub = 0;

            switch (ch)
            {
                case '\'':
                case '"':
                    string _value;
                    ReadQuote(ch, out _value);
                    value = ConvertData(_value, ch);
                    ReadBlank();
                    endtype = Read();

                    return;
                case '{':
                    JSON json = new JSON();
                    ReadToJSON(this, json, out endtype);
                    value = json;
                    return;
                case '[':
                    value = ReadArray(out endtype);
                    return;
                default:
                    while ((ch = Read()) > -1)
                    {
                        switch (ch)
                        {
                            case '}':
                            case ',':
                                sub = position;
                                goto BREAK_READ_PROP;
                            case ' ':
                            case '\r':
                            case '\n':
                            case '\t':
                                sub = position;
                                ReadBlank();
                                ch = Read();
                                goto BREAK_READ_PROP;
                        }
                    }
                    goto NO_RIGHT_END;
                BREAK_READ_PROP:
                    endtype = ch;
                    value = ConvertData(origin.Substring(start, sub - start - 1), -1);
                    return;
            }

            NO_RIGHT_END:
            value = null;
            endtype = -1;
            return;
        }
Esempio n. 4
0
        /// <summary>
        /// 从JsonReader的当前位置读一个JSON对象,并存储到参数中
        /// </summary>
        /// <param name="jr">源JR</param>
        /// <param name="json">写入对象</param>
        /// <param name="endtype">结束字符</param>
        public static void ReadToJSON(JsonReader jr, JSON json, out int endtype)
        {
            if (jr.Current != '{') throw new Exception("should be '['");

            QuoteString name;
            object value;
            int type;

            while (true)
            {
                jr.ReadPropertyName(out name);
                jr.ReadPorperty(out value, out type);
                json.Add(name, value);

                switch (type)
                {

                    case ',':
                        continue;
                    default:
                    case '}':
                        jr.ReadBlank();
                        type = jr.Read();
                        goto READ_END;
                }
            }

                READ_END:
                endtype = type;
        }