public static object Parse(object value) { string json = value as string; if (json != null && json.Length > 1) { char fc = json[0]; char lc = json[json.Length - 1]; if (fc == '{' && lc == '}' || fc == '[' && lc == ']') { byte[] data = System.Text.Encoding.UTF8.GetBytes(json); object res = new JsonReader().DeserializeBytes(data, data.Length); return res; } } return value; }
public static object Deserialize(Stream stream) { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int length = 0; int read = buffer.Length; while ((read = stream.Read(buffer, length, read)) > 0) { length += read; if (buffer.Length < length + read) { byte[] newBuffer = new byte[buffer.Length * 2]; Buffer.BlockCopy(buffer, 0, newBuffer, 0, length); buffer = newBuffer; } } object res = new JsonReader().DeserializeBytes(buffer, length); return res; }
public static object Deserialize(string text) { byte[] data = System.Text.Encoding.UTF8.GetBytes(text); object res = new JsonReader().DeserializeBytes(data, data.Length); return res; }
public static object Deserialize(byte[] data, int length) { object res = new JsonReader().DeserializeBytes(data, length); return res; }
public static object Deserialize(MemoryStream stream) { object res = new JsonReader().DeserializeBytes(stream.GetBuffer(), (int)stream.Length); return res; }