コード例 #1
0
        /// <summary>
        /// Make an JSON external form string of this JsonArray. For
        /// compactness, no unnecessary whitespace is added.
        /// </summary>
        /// <remarks>
        /// This method assumes that the data structure is acyclical.
        /// </remarks>

        public override string ToString()
        {
            StringWriter writer = new StringWriter();

            Export(JsonText.CreateWriter(writer));
            return(writer.ToString());
        }
コード例 #2
0
        public virtual object Invoke(Type returnType, string method, object args)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (method.Length == 0)
            {
                throw new ArgumentException(null, "method");
            }
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }

            WebRequest request = GetWebRequest(new Uri(Url));

            request.Method = "POST";

            using (Stream stream = request.GetRequestStream())
                using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                {
                    JsonObject call = new JsonObject();
                    call["id"]     = ++_id;
                    call["method"] = method;
                    call["params"] = args != null ? args : _zeroArgs;
                    JsonConvert.Export(call, writer);
                }

            using (WebResponse response = GetWebResponse(request))
                using (Stream stream = response.GetResponseStream())
                    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                        return(OnResponse(JsonText.CreateReader(reader), returnType));
        }
コード例 #3
0
        /// <summary>
        /// Returns the content of the buffer formatted as JSON text.
        /// </summary>

        public override string ToString()
        {
            if (IsEmpty)
            {
                return(string.Empty);
            }
            if (IsNull)
            {
                return(JsonNull.Text);
            }
            if (FirstToken.Class == JsonTokenClass.String)
            {
                return(JsonString.Enquote(FirstToken.Text));
            }
            if (IsScalar)
            {
                return(FirstToken.Text);
            }
            StringBuilder sb = new StringBuilder();

            JsonText.CreateWriter(sb).WriteFromReader(CreateReader());
            return(sb.ToString());
        }
コード例 #4
0
 public static JsonBuffer From(string json)
 {
     return(From(JsonText.CreateReader(json)));
 }