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; }
//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(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; } } } }
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); }
public static IJsonNode Parse(string json) { //try //{ ScanObj obj = new ScanObj(); obj.json = json; obj.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; isNull = 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 = MyJson.ScanFirst(c); if (node != null) { scan.seed = i; node.Scan(scan); i = scan.seed - 1; this.Add(node); } } }