public void Scan(ScanObj scan)
        {
            string _value = "";

            for (int i = scan.Seed + 1; i < scan.Json.Length; i++)
            {
                char c = scan.Json[i];
                if (c == '\\')
                {
                    i++;
                    c       = scan.Json[i];
                    _value += c;
                }

                else if (c != '\"')
                {
                    _value += c;
                }

                else
                {
                    scan.Seed = i + 1;
                    break;
                }
            }
            value = _value;
        }
Exemple #2
0
        //public 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(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 = JsonHelper.ScanFirst(c);
                    if (node != null)
                    {
                        scan.Seed = i;
                        node.Scan(scan);
                        i = scan.Seed - 1;
                        this.Add(key, node);
                        keystate = 0;
                    }
                }
            }
        }
Exemple #3
0
 internal static IJsonNode Scan(ScanObj scan)
 {
     for (int i = 0; i < scan.Json.Length; i++)
     {
         IJsonNode node = ScanFirst(scan.Json[i]);
         if (node != null)
         {
             scan.Seed = i;
             node.Scan(scan);
             return(node);
         }
     }
     return(null);
 }
Exemple #4
0
 public static IJsonNode Parse(string json)
 {
     try
     {
         ScanObj obj = new ScanObj
         {
             Json = json,
             Seed = 0
         };
         IJsonNode node = Scan(obj);
         return(node);
     }
     catch (Exception err)
     {
         throw new Exception("parse err:" + json, err);
     }
 }
        public void Scan(ScanObj scan)
        {
            string number = "";

            for (int i = scan.Seed; i < scan.Json.Length; i++)
            {
                char c = scan.Json[i];
                if (c != ',' && c != ']' && c != '}' && c != ' ')
                {
                    if (c != '\n')
                    {
                        number += c;
                    }
                }
                else
                {
                    scan.Seed = i;
                    break;
                }
            }

            if (number.ToLower() == "true")
            {
                Value  = 1;
                isBool = true;
            }
            else if (number.ToLower() == "false")
            {
                Value  = 0;
                isBool = true;
            }
            else if (number.ToLower() == "null")
            {
                Value  = 0;
                isBool = true;
            }
            else
            {
                Value  = double.Parse(number);
                isBool = false;
            }
        }
 public void Scan(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 = JsonHelper.ScanFirst(c);
         if (node != null)
         {
             scan.Seed = i;
             node.Scan(scan);
             i = scan.Seed - 1;
             this.Add(node);
         }
     }
 }