public static JSONResponse GetResponse(Stream stream) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONResponse)); JSONResponse req = (JSONResponse)ser.ReadObject(stream); return(req); }
public static String GetResponse(Boolean sucess, String error, String data) { String ret = ""; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONResponse)); JSONResponse r = new JSONResponse(); r.response = (sucess ? "success" : "failed"); r.error = error; r.data = data; using (MemoryStream ms = new MemoryStream()) { ser.WriteObject(ms, r); ms.Flush(); ret = Encoding.UTF8.GetString(ms.ToArray()); } return(ret); }