本文整理汇总了C#中Jayrock.Json.JsonObject.Export方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.Export方法的具体用法?C# JsonObject.Export怎么用?C# JsonObject.Export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jayrock.Json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.Export方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public virtual object Invoke(string method, params object[] args)
{
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;
call.Export(new JsonTextWriter(writer));
}
using (WebResponse response = GetWebResponse(request))
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
JsonObject answer = new JsonObject();
answer.Import(new JsonTextReader(reader));
object errorObject = answer["error"];
if (errorObject != null)
OnError(errorObject);
return answer["result"];
}
}
示例2: Invoke
public virtual object Invoke(string method, params object[] args)
{
string action = method + "(" + Util.ArrayToStringGeneric(args, ", ") + ") ";
//Console.WriteLine(action);
return Util.RetryAction<object>(() =>
{
WebRequest request = GetWebRequest(new Uri(Url));
request.Method = "POST";
request.Timeout = 45000;
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;
call.Export(new JsonTextWriter(writer));
}
using (HttpWebResponse response = (HttpWebResponse)GetWebResponse(request))
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
JsonObject answer = new JsonObject();
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception(action + "got Bad HTTP response: " + response.StatusCode);
}
else
{
answer.Import(new JsonTextReader(reader));
}
object errorObject = answer["error"];
if (errorObject != null)
OnError(errorObject);
return answer["result"];
}
}, action, 20, 100); // retry with delay
throw new Exception(action + "failed, too many retries");
}
示例3: Export
public void Export()
{
JsonObject o = new JsonObject();
o.Put("Number", 123);
o.Put("String", "Hello World");
o.Put("Boolean", true);
JsonRecorder writer = new JsonRecorder();
o.Export(writer);
JsonReader reader = writer.CreatePlayer();
reader.ReadToken(JsonTokenClass.Object);
string[] members = (string[]) o.GetNamesArray().ToArray(typeof(string));
Assert.AreEqual(members[0], reader.ReadMember());
Assert.AreEqual(o[members[0]], reader.ReadNumber().ToInt32());
Assert.AreEqual(members[1], reader.ReadMember());
Assert.AreEqual(o[members[1]], reader.ReadString());
Assert.AreEqual(members[2], reader.ReadMember());
Assert.AreEqual(o[members[2]], reader.ReadBoolean());
Assert.AreEqual(JsonTokenClass.EndObject, reader.TokenClass);
}
示例4: CannotUseNullArgWithExport
public void CannotUseNullArgWithExport()
{
IJsonExportable o = new JsonObject();
o.Export(null, null);
}
示例5: CallMethod
public JsonWsp.Response CallMethod(string methodname, JsonObject args, Dictionary<String, String> cookies = null, Dictionary<String, String> headers = null)
{
JsonObject req_dict = new JsonObject();
req_dict.Add("methodname",methodname);
req_dict.Add("type","jsonwsp/request");
req_dict.Add("args",args);
JsonWriter json_req_writer = new JsonTextWriter();
req_dict.Export(json_req_writer);
Dictionary<String, String> cookieList = m_cookieList;
if (cookies != null)
{
foreach (String key in cookies.Keys)
{
cookieList[key] = cookies[key];
}
}
Dictionary<String, String> headerList = m_headerList;
if (headers != null)
{
foreach (String key in headers.Keys)
{
headerList[key] = headers[key];
}
}
string content_type = "application/json; charset=utf-8";
JsonWsp.Response jsonwsp_response = SendRequest(m_service_url, json_req_writer.ToString(),content_type, cookieList, headerList);
// Convert response text
return jsonwsp_response;
}