コード例 #1
0
ファイル: MyJson.cs プロジェクト: zhangf911/LSharp
        //public MyJson.IJsonNode  this[string key]
        //{
        //    get
        //    {
        //        if (this.ContainsKey(key))
        //        {
        //            return base[key];
        //        }

        //        throw new Exception("key not exist");

        //    }
        //    set
        //    {
        //        if (value == null)
        //        {

        //            throw new Exception("value is null. key:"+key);
        //        }
        //        base[key] = value;
        //    }
        //}

        public void Scan(MyJson.ScanObj scan)
        {
            string key      = null;
            int    keystate = 0;//0 nokey 1scankey 2gotkey

            for (int i = scan.seed + 1; i < scan.json.Length; i++)
            {
                char c = scan.json[i];
                if (keystate != 1 && (c == ',' || c == ':'))
                {
                    continue;
                }
                if (c == '}')
                {
                    scan.seed = i + 1;
                    break;
                }
                if (keystate == 0)
                {
                    if (c == '\"')
                    {
                        keystate = 1;
                        key      = "";
                    }
                }
                else if (keystate == 1)
                {
                    if (c == '\"')
                    {
                        keystate = 2;
                        //scan.seed = i + 1;
                        continue;
                    }
                    else
                    {
                        key += c;
                    }
                }
                else
                {
                    IJsonNode node = MyJson.ScanFirst(c);
                    if (node != null)
                    {
                        scan.seed = i;
                        node.Scan(scan);
                        i = scan.seed - 1;
                        this.Add(key, node);
                        keystate = 0;
                    }
                }
            }
        }
コード例 #2
0
        public void Scan(MyJson.ScanObj scan)
        {
            for (int i = scan.seed + 1; i < scan.json.Length; i++)
            {
                char c = scan.json[i];
                if (c == ',')
                    continue;
                if (c == ']')
                {
                    scan.seed = i + 1;
                    break;
                }
                IJsonNode node = MyJson.ScanFirst(c);
                if (node != null)
                {
                    scan.seed = i;
                    node.Scan(scan);
                    i = scan.seed - 1;
                    this.Add(node);
                }

            }
        }