public override bool TrySetMember(SetMemberBinder binder, object value) { JsonItem jitem = this.Find(binder.Name); bool flag = jitem != null; if (flag) { jitem.Value = value; } else { if (value is JsonItem jsitem) { jsitem.Name = binder.Name; jsitem.Parent = this; jsitem.Index = this.SubItems.Count; this.SubItems.Add(jsitem); } else { jitem = new JsonItem { Parent = this, Name = binder.Name }; JsonDecoder.DecodeFrom(value, jitem); jitem.Index = this.SubItems.Count; this.SubItems.Add(jitem); } } return(true); }
public static JsonItem Decode(string input, bool skipcomment = false) { JsonDecoder jparser = new JsonDecoder { skipComment = skipcomment, DecodeUnicode = true }; return(jparser.DecodeJson(input)); }
public static JsonItem DecodeFrom(object item, JsonItem baseitem = null) { JsonDecoder jparser = new JsonDecoder(); JsonItem jitem = baseitem; if (jitem == null) { jitem = new JsonItem(); } HashSet <object> recursion = new HashSet <object>(); JsonItem parent = jitem.Parent; if (parent != null && parent.ObjectType == JsonItemType.OBJ_ARRAY) { jitem.ObjectType = JsonItemType.OBJ_ARRAYITEM; } else { JsonItem parent2 = jitem.Parent; if (parent2 != null && parent2.ObjectType == JsonItemType.OBJ_OBJECT) { jitem.ObjectType = JsonItemType.OBJ_VARIANT; } } if (jitem == null) { jitem = new JsonItem(); } if (item.IsArray()) { jitem.ObjectType = JsonItemType.OBJ_ARRAY; jitem.SubItems = jparser.JsonDecodeFromArray((IList)item, jitem, recursion); } else { if (item.IsObject() || item.IsDictionary()) { jitem.ObjectType = JsonItemType.OBJ_OBJECT; if (item is IDictionary || item is IDictionary <string, object> ) { jitem.SubItems = jparser.JsonDecodeFromDictionary((IEnumerable)item, jitem, recursion); } else { jitem.SubItems = jparser.JsonDecodeFromObject(item, jitem, recursion); } } else { jitem.Value = item; } } recursion.Clear(); return(jitem); }