internal JSonMutableArray(JSonArray array) : base(true) { if (array == null) throw new ArgumentNullException("array"); foreach (var item in array.Data) Data.Add(item.CreateMutableClone()); }
internal JSonMutableArray(JSonArray array) : base(true) { if (array == null) { throw new ArgumentNullException("array"); } foreach (var item in array.Data) { Data.Add(item.CreateMutableClone()); } }
public static JSon Deserialize(StringReader reader) { char car; do { car = (char)reader.Peek(); JSon res = null; switch (car) { case '{': reader.Read(); res = new JSonObject(); break; case '[': reader.Read(); res = new JSonArray(); break; case '"': reader.Read(); res = new JSonString(); break; case var x when(x >= '0' && x <= '9') || (x == '-'): res = new JSonInt(); break; } if (res != null) { res.Parse(reader); return(res); } reader.Read(); } while (car == ' ' || car == '\n'); return(null); }
/// <summary> /// Creates new instance of mutable JSON array object filled with given data. /// </summary> internal static IJSonMutableObject CreateArray(JSonArray array) { return(new JSonMutableArray(array)); }
//**************************************************************************************************** // //**************************************************************************************************** public bool Parse(string json) { if (string.IsNullOrEmpty(json)) { return(false); } ControlStack ctrl = new ControlStack(); JSonEntry cur = null; string name = null; m_root = null; for (int c = 0; c < json.Length; ++c) { //-------------------------------------------------------------------------------------------- // register expression //-------------------------------------------------------------------------------------------- if (char.IsWhiteSpace(json[c]) == false) { if (Semantics.hasProps(json[c], Semantics.PROP.ALL) == false) { if (ctrl.expr.start == -1) { ctrl.expr.end = ctrl.expr.start = c; } else { ctrl.expr.end = c; } if (json[c] == QUOTE) { ++ctrl.expr.quotes; continue; } } } else { continue; } //-------------------------------------------------------------------------------------------- // register name or value //-------------------------------------------------------------------------------------------- if (Semantics.hasProps(json[c], Semantics.PROP.CTRL) == true) { if ((ctrl.expr.quotes & 1) == 0) { bool isName = (json[c] == COLON); bool isValue = (isName == false); bool valid = ctrl.expr.valid; if ((isName) && (valid == false)) { return(false); } if ((isName) && (cur is JSonObject) == false) { return(false); } if (valid) { string expr = json.Substring(ctrl.expr.start, ctrl.expr.end - ctrl.expr.start + 1).TrimEnd(' ', QUOTE, ' ').TrimStart(' ', QUOTE, ' '); if (isName) { name = expr; } else if (isValue) { new JSonValue(name, cur).value = expr; name = null; } } ctrl.expr.Reset(); if (Semantics.hasProps(json[c], Semantics.PROP.GRP) == false) { continue; } } } //-------------------------------------------------------------------------------------------- // register object or array //-------------------------------------------------------------------------------------------- if (ctrl.expr.quotes == 0) { if (json[c] == BGN_OBJ) { if ((cur == null) || ctrl.push(cur)) { cur = new JSonObject(name, cur); if (m_root == null) { m_root = cur; } name = null; ctrl.expr.Reset(); continue; } else { return(false); } } if (json[c] == BGN_ARR) { if ((cur == null) || ctrl.push(cur)) { cur = new JSonArray(name, cur); if (m_root == null) { m_root = cur; } name = null; ctrl.expr.Reset(); continue; } else { return(false); } } if (json[c] == END_OBJ) { if (cur == m_root) { break; } if ((cur is JSonObject) && ctrl.pop(ref cur)) { ctrl.expr.Reset(); continue; } else { return(false); } } if (json[c] == END_ARR) { if (cur == m_root) { break; } if ((cur is JSonArray) && ctrl.pop(ref cur)) { ctrl.expr.Reset(); continue; } else { return(false); } } } } return((m_root != null) && (ctrl.empty)); }
/// <summary> /// Creates new instance of mutable JSON array object filled with given data. /// </summary> internal static IJSonMutableObject CreateArray(JSonArray array) { return new JSonMutableArray(array); }