public void ContainsExistingViaGenericCollection() { ICollection <KeyValuePair <string, object> > obj = new JsonObject(); obj.Add(new KeyValuePair <string, object>("first", 123)); Assert.IsTrue(obj.Contains(new KeyValuePair <string, object>("first", 123))); }
public void ContainsNonExistingKeyMatchingValueViaGenericCollection() { ICollection <KeyValuePair <string, object> > obj = new JsonObject(); obj.Add(new KeyValuePair <string, object>("first", 123)); Assert.IsFalse(obj.Contains(new KeyValuePair <string, object>("second", 123))); }
public void ContainsNonExistingViaGenericCollection() { ICollection<KeyValuePair<string, object>> obj = new JsonObject(); obj.Add(new KeyValuePair<string, object>("first", 123)); Assert.IsFalse(obj.Contains(new KeyValuePair<string, object>("second", 456))); }
/** * @param json * @return module id from the request, or null if not present * @throws JSONException */ private static string getModuleId(JsonObject json) { if (json.Contains("moduleId")) { return json["moduleId"].ToString(); } return null; }
/** * Parse the steps in the path into JSON Objects. */ static JsonObject BuildHolder(JsonObject root, String[] steps, int currentStep) { if (currentStep > steps.Length - 2) { return root; } Match matcher = ARRAY_MATCH.Match(steps[currentStep]); if (matcher.Success) { // Handle as array String fieldName = matcher.Groups[1].Value; int index = int.Parse(matcher.Groups[2].Value); JsonArray newArrayStep; if (root.Contains(fieldName)) { newArrayStep = root[fieldName] as JsonArray; } else { newArrayStep = new JsonArray(); root.Put(fieldName, newArrayStep); } JsonObject newStep = new JsonObject(); newArrayStep[index] = newStep; return BuildHolder(newStep, steps, ++currentStep); } else { JsonObject newStep; if (root.Contains(steps[currentStep])) { newStep = root[steps[currentStep]] as JsonObject; } else { newStep = new JsonObject(); root.Put(steps[currentStep], newStep); } return BuildHolder(newStep, steps, ++currentStep); } }
/// <summary> /// Create an item from json code /// </summary> /// <param name="jsonObject">the json object to parse</param> public ServerListItem(JsonObject jsonObject) { if (jsonObject.Contains("name")) Name = jsonObject["name"].ToString(); if (jsonObject.Contains("ip")) Ip = jsonObject["ip"].ToString(); if (jsonObject.Contains("uuid")) Uuid = jsonObject["uuid"].ToString(); if (jsonObject.Contains("level")) OpLevel = int.Parse(jsonObject["level"].ToString()); if (jsonObject.Contains("created")) Created = jsonObject["created"].ToString(); if (jsonObject.Contains("source")) Source = jsonObject["source"].ToString(); if (jsonObject.Contains("expires")) Expires = jsonObject["expires"].ToString(); if (jsonObject.Contains("reason")) Reason = jsonObject["reason"].ToString(); }
public static string getArrayItem(JsonObject ob, string arrayname, int arrayind) { if (ob == null || !ob.Contains(arrayname)) return ""; if (!(ob[arrayname] is JsonArray)) return ""; JsonArray arr = (JsonArray)ob[arrayname]; if (arr.Length < arrayind) return ""; return Converter.toString(arr[arrayind]); }
private void dispatch(JsonObject request, HttpResponse servletResponse, ISecurityToken token) { String key = null; if (request.Contains("id")) { key = request["id"] as String; } RpcRequestItem requestItem = new RpcRequestItem(request, token, jsonConverter); // Resolve each Future into a response. // TODO: should use shared deadline across each request ResponseItem response = getResponseItem(HandleRequestItem(requestItem)); Object result = getJsonResponse(key, response, requestItem); servletResponse.Output.Write(jsonConverter.ConvertToString(result)); }
/** * Inspects the passed object for one of several specific properties and, if * found, returns that property as a JsonObject object. All valid response * objects which encapsulate a single data item (e.g. a person) must have * this property. * * @param root JsonObject to query for the presence of the specific property * @throws OpenSocialRequestException if property is not found _in the passed * object * @throws JSONException */ private static JsonObject getEntryObject(JsonObject root) { JsonObject entry = new JsonObject(); if (root.Contains("data")) { entry = root.getJSONObject("data"); } else if (root.Contains("entry")) { entry = root.getJSONObject("entry"); } else { throw new OpenSocialRequestException("Entry not found"); } return entry; }
/** * Inspects the passed object for one of several specific properties and, if * found, returns that property as a JsonArray object. All valid response * objects which contain a data collection (e.g. a collection of people) * must have this property. * * @param root JsonObject to query for the presence of the specific property * @throws OpenSocialRequestException if property is not found _in the passed * object * @throws JSONException */ private static JsonArray getEntryArray(JsonObject root) { JsonArray entry = new JsonArray(); if (root.Contains("entry")) { entry = (JsonArray)root["entry"]; } else if (root.Contains("data")) { entry = (JsonArray)root.getJSONObject("data")["list"]; } else { throw new OpenSocialRequestException("Entry not found"); } return entry; }