Пример #1
0
        public string ReComposeJson_Delete(string json_in)
        {
            json_get_delete_data json_from_WebAPI;

            //de-serialize json string from web api.
            using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json_in)))
            {
                DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(typeof(json_get_delete_data));
                json_from_WebAPI = (json_get_delete_data)deseralizer.ReadObject(ms);// //反序列化ReadObject
            }

            //put together as new serialize json string as server need
            json_srv_delete json_to_srv = new json_srv_delete();
            string          ret_str;

            using (var ms = new MemoryStream())
            {
                DataContractJsonSerializer seralizer = new DataContractJsonSerializer(typeof(json_srv_delete));

                //assign one json to another json
                json_to_srv.clientUserId = json_from_WebAPI.data.clientUserId;
                json_to_srv.deleteData   = json_from_WebAPI.data.deleteData;

                //write to stream
                seralizer.WriteObject(ms, json_to_srv);
                ms.Position = 0;
                StreamReader sr = new StreamReader(ms, Encoding.UTF8);
                ret_str = sr.ReadToEnd();
                sr.Close();
            }
            return(ret_str);
        }
Пример #2
0
        public string BuildJson_Delete(string clientUserId, string deleteData)
        {
            //put together as new serialize json string as server need
            json_srv_delete json_to_srv = new json_srv_delete();
            string          ret_str;

            using (var ms = new MemoryStream())
            {
                DataContractJsonSerializer seralizer = new DataContractJsonSerializer(typeof(json_srv_delete));

                //assign one json to another json
                json_to_srv.clientUserId = clientUserId;
                json_to_srv.deleteData   = deleteData;

                //write to stream
                seralizer.WriteObject(ms, json_to_srv);
                ms.Position = 0;
                StreamReader sr = new StreamReader(ms, Encoding.UTF8);
                ret_str = sr.ReadToEnd();
                sr.Close();
            }
            return(ret_str);
        }