/// <summary> /// Create a deep copy of this instance. /// </summary> public IJSONValue DeepCopy() { IJSONValue copy = CreatePrototype(); copy.CopyValue(this); return(copy); }
/// <summary> /// Read a JSON value. /// </summary> /// <param name="path">JSON path to the value we're reading</param> /// <param name="pbr">a pushback reader</param> /// <returns>the next JSON value</returns> /// <exception cref="System.IO.IOException" /> /// <exception cref="Gavaghan.JSON.JSONException" /> public IJSONValue Read(string path, PushbackReader pbr) { IJSONValue value; char c = Demand(pbr); // is it a string? if (c == '\"') { value = OnString(path, pbr); } // is it a number? else if (Char.IsDigit(c) || (c == '-')) { value = OnNumber(path, pbr); } // is it an array? else if (c == '[') { value = OnArray(path, pbr); } // is it an object? else if (c == '{') { value = OnObject(path, pbr); } // is it a boolean? else if ((c == 't') || (c == 'f')) { value = OnBoolean(path, pbr); } // is it a null? else if (c == 'n') { value = OnNull(path, pbr); } // else, value type else { value = OnUnknown(path, pbr, c); } // unread trigger character pbr.Unread(c); // implementation specific read value.Read(path, pbr); // give subtype a chance to select a different implementation IJSONValue recast = Recast(path, value); // if value was recast, copy over original data if (recast != null) { recast.CopyValue(value); value = recast; } return(value); }