ToJson() public method

Serializes an object to a string
Object definition must have the [Serializable] attribute. Serializes only members which are not marked with [NonSerialized] attribute.
public ToJson ( object o ) : string
o object Object to be serialized
return string
Exemplo n.º 1
0
        private WebResponse MakeRequest(string url, object obj, string Method, string id, string key)
        {
            //lock (this)
            //{
            Debug.Print("Request: " + url);
            using (HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest)
            {

                req.Method = Method;
                req.ContentType = ContentType;
                req.KeepAlive = false;
                req.Headers.Add(IdHeader, id);
                req.Headers.Add(KeyHeader, key);
                req.ReadWriteTimeout = AsyncTimeout;
                req.Timeout = AsyncTimeout;
                if (obj != null)
                {
                    JsonFormatter js = new JsonFormatter();

                    string s = js.ToJson(obj);
                    req.ContentLength = s.Length;
                    using (Stream rs = req.GetRequestStream())
                    {
                        rs.Write(Encoding.UTF8.GetBytes(s), 0, s.Length);
                        rs.Close();
                    }
                }

                HttpWebResponse resp = GetResponseAsync(req); //(HttpWebResponse)req.GetResponse(); //
                Debug.Print("Done. Response code = " + resp.StatusCode.ToString());
                return resp;
            }
          
        }