本文整理汇总了C#中Jayrock.Json.JsonObject.Put方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.Put方法的具体用法?C# JsonObject.Put怎么用?C# JsonObject.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jayrock.Json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.Put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
string action = context.Request.Form["Action"];
context.Response.Clear();
context.Response.ContentType = "application/json";
try
{
switch (action)
{
#region 本月账单
case "currentMon":
TradeLsit(context, action);
break;
#endregion
#region 全部账单
case "allMon":
TradeLsit(context, action);
break;
#endregion
default:
break;
}
}
catch (Exception ex)
{
JsonObject json = new JsonObject();
json.Put(TAO_KEY_STATUS, TAO_STATUS_ERROR);
json.Put(TAO_KEY_DATA, ex);
context.Response.Write(json.ToString());
}
}
示例2: FromRequest
public static JsonObject FromRequest(HttpRequest request)
{
//String methodName = request.getPathInfo().replaceAll("/", "");
JsonObject root = new JsonObject();
NameValueCollection parameters = request.Params;
root.Put("method", parameters["method"]);
if (!string.IsNullOrEmpty(parameters.Get("id")))
{
root.Put("id", parameters["id"]);
}
JsonObject paramsRoot = new JsonObject();
for (int i = 0; i < parameters.Count; i++)
{
if (!RESERVED_PARAMS.Contains(parameters.GetKey(i).ToLower()))
{
String[] path = parameters.GetKey(i).Split('\\');
JsonObject holder = BuildHolder(paramsRoot, path, 0);
holder.Put(path[path.Length - 1], ConvertToJsonValue(parameters.GetValues(i)[0]));
}
}
if (paramsRoot.Count > 0)
{
root.Put("params", paramsRoot);
}
return root;
}
示例3: ToString
public override string ToString()
{
JsonObject serialized = new JsonObject();
serialized.Put(KEY_MMSI, this.Mmsi);
serialized.Put(KEY_NAME, this.Name);
return serialized.ToString();
}
示例4: FromException
public static JsonObject FromException(Exception e, bool includeStackTrace)
{
if (e == null)
throw new ArgumentNullException("e");
JsonObject error = new JsonObject();
error.Put("name", "JSONRPCError");
error.Put("message", e.GetBaseException().Message);
if (includeStackTrace)
error.Put("stackTrace", e.StackTrace);
JsonArray errors = new JsonArray();
do
{
errors.Put(ToLocalError(e));
e = e.InnerException;
}
while (e != null);
error.Put("errors", errors);
return error;
}
示例5: Names
public void Names()
{
JsonObject o = new JsonObject();
o.Put("one", 1);
o.Put("two", 2);
ICollection names = o.Names;
IEnumerator e = names.GetEnumerator();
e.MoveNext(); Assert.AreEqual("one", e.Current);
e.MoveNext(); Assert.AreEqual("two", e.Current);
}
示例6: ToLocalError
private static JsonObject ToLocalError(Exception e)
{
Debug.Assert(e != null);
JsonObject error = new JsonObject();
error.Put("name", e.GetType().Name);
error.Put("message", e.Message);
return error;
}
示例7: ProcessRequest
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
JsonObject json = new JsonObject();
if (!string.IsNullOrEmpty(Request.Form["cid"]) && !string.IsNullOrEmpty(Request.Form["mids"]) && !string.IsNullOrEmpty(Request.Form["uid"]) && !string.IsNullOrEmpty(Request.Form["uEmail"]) && !string.IsNullOrEmpty(Request.Form["uName"]) && !string.IsNullOrEmpty(Request.Form["SellerId"]) && !string.IsNullOrEmpty(Request.Form["tprice"]))
{
int cid = int.Parse(Request.Form["cid"]);
string mids = Request.Form["mids"];
int type = -1;
if(mids.Contains(','))
{
mids = mids.TrimEnd(',');
type = 1;
}
else
{
type = 0;
}
int uid = int.Parse(Request.Form["uid"]);
string email = Request.Form["uEmail"];
int sellerId = int.Parse(Request.Form["SellerId"]);
decimal totalPrice = decimal.Parse(Request.Form["tprice"]);
string uName = Request.Form["uName"];
Model.Tao.Orders orderList = new Model.Tao.Orders();
orderList.BuyerID = uid;
orderList.Email = email;
orderList.Amount = totalPrice;
orderList.UserName = uName;
orderList.SellerID = sellerId;
BLL.Tao.Orders orderBll = new BLL.Tao.Orders();
int OId = orderBll.CreateNewOrderInfo(orderList, cid, mids, type);
if (OId > 0)
{
json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS);
json.Put(TAO_KEY_DATA, OId);
}
else
{
json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED);
}
}
else
{
json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED);
}
context.Response.Write(json.ToString());
}
示例8: FromException
public static JsonObject FromException(Exception e, bool includeStackTrace)
{
if (e == null)
throw new ArgumentNullException("e");
JsonObject error = new JsonObject();
error.Put("name", "JSONRPCError");
error.Put("message", e.GetBaseException().Message);
if (includeStackTrace)
error.Put("stackTrace", e.StackTrace);
return error;
}
示例9: getResponseAsJson
/**
* Convert a response to a JSON object. static so it can be used by HttpPreloaders as well.
*
* The returned JSON object contains the following values:
* rc: integer response code
* body: string response body
* headers: object, keys are header names, values are lists of header values
*
* @param response the response body
* @param body string to use as the body of the response.
* @return a JSONObject representation of the response body.
*/
public static JsonObject getResponseAsJson(sResponse response, String body)
{
JsonObject resp = new JsonObject();
resp.Put("rc", response.getHttpStatusCode());
resp.Put("body", body);
JsonObject headers = new JsonObject();
addHeaders(headers, response, "set-cookie");
addHeaders(headers, response, "location");
resp.Put("headers", headers);
// Merge in additional response data
foreach (var entry in response.getMetadata())
{
resp.Put(entry.Key, entry.Value);
}
return resp;
}
示例10: ContentsClearedBeforeImporting
public void ContentsClearedBeforeImporting()
{
JsonObject o = new JsonObject();
o.Put("foo", "bar");
Assert.AreEqual(1, o.Count);
o.Import(new JsonTextReader(new StringReader("{}")));
Assert.AreEqual(0, o.Count);
}
示例11: addHeaders
private static void addHeaders(JsonObject headers, sResponse response, String headerName)
{
string[] values = response.getHeaders(headerName);
if (values != null)
{
headers.Put(headerName.ToLower(), new JsonArray(values));
}
}
示例12: Load
private JsonObject Load(RegistryKey root)
{
JsonObject jo = new JsonObject();
using (RegistryKey key = root != null ? root : GetRootKey(false))
{
if (!this.GetType().ToString().Equals(key.GetValue("")))
throw new Exception("Not for this class"); // TODO: find a better Exception
foreach (string valueName in key.GetValueNames())
{
if (!valueName.Equals(""))
jo.Put(valueName, key.GetValue(valueName));
}
foreach (string subKeyName in key.GetSubKeyNames())
{
jo.Put(subKeyName, Load(key.OpenSubKey(subKeyName)));
}
}
return jo;
}
示例13: 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);
}
示例14: Call
/// <summary>
/// Makes an API call given a method name and JSON argument object
/// </summary>
/// <param name="method">Method name (eg. earth911.searchLocations)</param>
/// <param name="args">JSON object containing method arguments</param>
/// <returns>JSON result (typically a JsonObject or JsonArray)</returns>
/// <exception cref="ApiError">Raised if an API error occurred</exception>
public object Call(string method, JsonObject args)
{
args.Put("api_key", this.apiKey);
string url = this.apiUrl + method + '?' + BuildQuery(args);
string text = GetURL(url);
JsonObject result = (JsonObject)JsonConvert.Import(text);
if (result["error"] != null)
{
throw new ApiError((string)result["error"]);
}
else
{
return result["result"];
}
}
示例15: ReadParameters
private static object ReadParameters(Method method, JsonReader reader, ImportContext importContext)
{
Debug.Assert(method != null);
Debug.Assert(reader != null);
Debug.Assert(importContext != null);
reader.MoveToContent();
Parameter[] parameters = method.GetParameters();
if (reader.TokenClass == JsonTokenClass.Array)
{
reader.Read();
ArrayList argList = new ArrayList(parameters.Length);
// TODO: This loop could bomb when more args are supplied that parameters available.
for (int i = 0; i < parameters.Length && reader.TokenClass != JsonTokenClass.EndArray; i++)
argList.Add(importContext.Import(parameters[i].ParameterType, reader));
reader.StepOut();
return argList.ToArray();
}
else if (reader.TokenClass == JsonTokenClass.Object)
{
reader.Read();
JsonObject argByName = new JsonObject();
while (reader.TokenClass != JsonTokenClass.EndObject)
{
// TODO: Imporve this lookup.
// FIXME: Does not work when argument is positional.
Type parameterType = AnyType.Value;
string name = reader.ReadMember();
foreach (Parameter parameter in parameters)
{
if (parameter.Name.Equals(name))
{
parameterType = parameter.ParameterType;
break;
}
}
argByName.Put(name, importContext.Import(parameterType, reader));
}
reader.Read();
return argByName;
}
else
{
return importContext.Import(reader);
}
}