本文整理汇总了C#中JsonTextWriter.WriteArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteArray方法的具体用法?C# JsonTextWriter.WriteArray怎么用?C# JsonTextWriter.WriteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Version1
//.........这里部分代码省略.........
{
writer.Write(parameter.Name);
writer.Write(", ");
}
writer.WriteLine("callback)");
writer.WriteLine("{");
writer.Indent++;
writer.Write("return call(\"");
writer.Write(method.Name);
writer.Write("\", [");
foreach (JsonRpcParameter parameter in parameters)
{
if (parameter.Position > 0)
writer.Write(',');
writer.Write(' ');
writer.Write(parameter.Name);
}
writer.WriteLine(" ], callback);");
writer.Indent--;
writer.WriteLine("}");
writer.WriteLine();
}
writer.Write("var url = typeof(url) === 'string' ? url : '");
writer.Write(url);
writer.WriteLine("';");
writer.WriteLine(@"var self = this;
var nextId = 0;
function call(method, params, callback)
{
var request = { id : nextId++, method : method, params : params };
return callback == null ?
callSync(method, request) : callAsync(method, request, callback);
}
function callSync(method, request)
{
var http = newHTTP();
http.open('POST', url, false, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.send(JSON.stringify(request));
if (http.status != 200)
throw { message : http.status + ' ' + http.statusText, toString : function() { return message; } };
var response = JSON.eval(http.responseText);
if (response.error != null) throw response.error;
return response.result;
}
function callAsync(method, request, callback)
{
var http = newHTTP();
http.open('POST', url, true, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.onreadystatechange = function() { http_onreadystatechange(http, callback); }
http.send(JSON.stringify(request));
return request.id;
}
function setupHeaders(http, method)
{
http.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
http.setRequestHeader('X-JSON-RPC', method);
}
function http_onreadystatechange(sender, callback)
{
if (sender.readyState == /* complete */ 4)
{
var response = sender.status == 200 ?
JSON.eval(sender.responseText) : {};
response.xmlHTTP = sender;
callback(response);
}
}
function newHTTP()
{
return typeof(ActiveXObject) === 'function' ?
new ActiveXObject('Microsoft.XMLHTTP') : /* IE 5 */
new XMLHttpRequest(); /* Safari 1.2, Mozilla 1.0/Firefox, and Netscape 7 */
}");
writer.Indent--;
writer.WriteLine("}");
writer.WriteLine();
writer.Write(service.Name);
writer.Write(".rpcMethods = ");
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.WriteArray(methodNames);
writer.WriteLine(";");
}
示例2: ProcessRequest
protected override void ProcessRequest()
{
string httpMethod = Request.RequestType;
if (!CaselessString.Equals(httpMethod, "GET") &&
!CaselessString.Equals(httpMethod, "HEAD"))
{
throw new JsonRpcException(string.Format("HTTP {0} is not supported for RPC execution. Use HTTP GET or HEAD only.", httpMethod));
}
//
// Response will be plain text, though it would have been nice to
// be more specific, like text/json.
//
Response.ContentType = "text/plain";
//
// Convert the query string into a call object.
//
JsonWriter writer = new JsonTextWriter();
writer.WriteStartObject();
writer.WriteMember("id");
writer.WriteNumber(0);
writer.WriteMember("method");
string methodName = Mask.NullString(Request.PathInfo);
if (methodName.Length == 0)
writer.WriteNull();
else
writer.WriteString(methodName.Substring(1));
writer.WriteMember("params");
writer.WriteStartObject();
NameValueCollection query = Request.QueryString;
if (query.HasKeys())
{
foreach (string name in query)
{
if (Mask.NullString(name).Length == 0)
continue;
writer.WriteMember(name);
string[] values = query.GetValues(name);
if (values.Length == 0)
writer.WriteNull();
else if (values.Length == 1)
writer.WriteString(values[0]);
else
writer.WriteArray(values);
}
}
writer.WriteEndObject();
writer.WriteEndObject();
//
// Delegate rest of the work to JsonRpcDispatcher.
//
JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(Service);
if (HttpRequestSecurity.IsLocal(Request))
dispatcher.SetLocalExecution();
dispatcher.Process(new StringReader(writer.ToString()), Response.Output);
}