Beispiel #1
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;
        }
Beispiel #2
0
 public JSON()
 {
     dic = new Dictionary<QuoteString, object>();
     _ArrayValue = null;
     jr = null;
 }
Beispiel #3
0
        /// <summary>
        /// 读取JSON字符串
        /// </summary>
        /// <param name="s"></param>
        public void Read(string s)
        {
            Clear();

            jr = new JsonReader(s);
            int type = jr.ReadToObjBegin();

            switch (type)
            {
                case '{':
                    JsonReader.ReadToJSON(jr, this, out type);
                    break;
                case '[':
                    _ArrayValue = jr.ReadArray(out type);
                    break;
                default:
                    throw new Exception("Unkonwn JSON format");
            }
        }