Exemple #1
0
        public static JSONResponse GetResponse(Stream stream)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONResponse));
            JSONResponse req = (JSONResponse)ser.ReadObject(stream);

            return(req);
        }
Exemple #2
0
        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);
        }