Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 public static object Deserialize(string text) {
     byte[] data = System.Text.Encoding.UTF8.GetBytes(text);
     object res = new JsonReader().DeserializeBytes(data, data.Length);
     return res;
 }
Пример #4
0
 public static object Deserialize(byte[] data, int length) {
     object res = new JsonReader().DeserializeBytes(data, length);
     return res;
 }
Пример #5
0
 public static object Deserialize(MemoryStream stream) {
     object res = new JsonReader().DeserializeBytes(stream.GetBuffer(), (int)stream.Length);
     return res;
 }