本文整理汇总了C#中System.Json.JsonValue.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValue.ContainsKey方法的具体用法?C# JsonValue.ContainsKey怎么用?C# JsonValue.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Json.JsonValue
的用法示例。
在下文中一共展示了JsonValue.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Populate
void Populate (JsonValue json, RootElement root, JsonValue data)
{
if (json.ContainsKey(Constants.Title))
root.Caption = json[Constants.Title];
JsonValue jsonRoot = null;
try {
jsonRoot = json[Constants.Root];
} catch (Exception){
Console.WriteLine("Bad JSON: could not find the root element - "+json.ToString()) ;
return;
}
if (json.ContainsKey(Constants.DataRoot)){
var dataroot = json[Constants.DataRoot].CleanString();
if (data!=null && data.ContainsKey(dataroot))
data = data[dataroot];
}
foreach (JsonObject section in jsonRoot){
var sec = new FormSectionBuilder(this._controller).Build(section, data);
foreach (var el in sec.Elements) {
if (!string.IsNullOrEmpty(el.ID) && !_elements.ContainsKey(el.ID)) _elements.Add(el.ID, el);
}
root.Add(sec);
}
}
示例2: Parser
internal Parser(JsonValue json)
{
_sourceparser = json;
MissingTokens = json.ContainsKey("missing_tokens")
? new HashSet<string>(json["missing_tokens"].Select(x => (string) x))
: new HashSet<string>();
}
示例3: GetString
public static string GetString(JsonValue obj, string key)
{
if (obj.ContainsKey(key))
if (obj[key].JsonType == JsonType.String)
return (string)obj[key];
return null;
}
示例4: FullQuestion
public FullQuestion(JsonValue jsonValue, Spin spin)
{
this.Spin = spin;
if (jsonValue.ContainsKey("powerup_question"))
this.PowerupQuestion = new Question(jsonValue["powerup_question"], this);
this.Question = new Question(jsonValue["question"], this);
}
示例5: ContainsKey
private static bool ContainsKey (JsonValue jsonValue, string key)
{
if (!jsonValue.ContainsKey (key)) {
LogContext.Current.Log<JsonUtil> ("JsonValueString: Missing key", key);
return false;
} else
return true;
}
示例6: CheckForLandmark
public static string CheckForLandmark (JsonValue searchResult, string locationName)
{
string result = "";
result = (
searchResult.ContainsKey ("types") ? (searchResult ["types"] as JsonArray).ToList () : new List<JsonValue> ()
).Exists (v =>
v == "stadium" // build this out as necessary with valid types from here https://developers.google.com/places/documentation/supported_types
) ? locationName : "";
return result;
}
示例7: AddApp
internal void AddApp(int appId, JsonValue app, JsonValue engines)
{
var matches = new List<PathMatch>();
if (app.ContainsKey(Key))
{
matches.AddRange(app[Key].Select(match => new PathMatch(match.Value)));
}
if (app.ContainsKey("engine"))
{
var args = app["engine"];
var engine = engines[(string) args["name"]];
if (engine.ContainsKey(Key))
{
matches.AddRange(engine[Key].Select(match => new PathMatch(match.Value, args)));
}
}
Apps[appId] = matches;
}
示例8: GetQuietTime
static QuietTime GetQuietTime(JsonValue jsonValue)
{
if (jsonValue.ContainsKey("quiettime"))
{
var quiettime = jsonValue["quiettime"];
return new QuietTime
{
Start = quiettime.StringValue("start"),
End = quiettime.StringValue("end"),
};
}
return null;
}
示例9: DecodeLoginResponse
public static LoginResponse DecodeLoginResponse (JsonValue json)
{
LoginResponse response = new LoginResponse ();
if (json == null) {
response.StatusCode = Response.UnknownError;
return response;
}
if (json.ContainsKey (STATUS)) {
response.StatusCode = json [STATUS];
} else if (json.ContainsKey (EXCEPTION)) {
response.StatusCode = json [EXCEPTION];
}
if (json.ContainsKey (UserInfo.SESSIONID)) {
response.SessionId = json [UserInfo.SESSIONID];
}
if (json.ContainsKey (UserInfo.NAME)) {
response.Name = json [UserInfo.NAME];
}
if (json.ContainsKey (UserInfo.EMAIL)) {
response.email = json [UserInfo.EMAIL];
}
// if (!response.IsOk) {
// if (json.ContainsKey (MESSAGE)) {
// response.Message = json [MESSAGE];
// } else if (json.ContainsKey ("msg")) {
// response.Message = json ["msg"];
// }
// }
return response;
}
示例10: Session
public Session(JsonValue json)
: this()
{
Id = json["id"];
Title = json["title"];
Abstract = json["abstract"];
Location = json["location"];
var begins = json["begins"].ToString().Trim ('"').Substring (0, 19).Replace ("T", " ");
Begins = DateTime.Parse (begins);
if (json.ContainsKey("ends"))
{
var ends = json["ends"].ToString().Trim('"').Substring(0, 19).Replace("T", " ");
Ends = DateTime.Parse(ends, System.Globalization.CultureInfo.InvariantCulture);
}
}
示例11: VBUser
public VBUser(JsonValue json) {
DB_Communicator db = DB_Communicator.getInstance();
this.idUser = db.convertAndInitializeToInt(db.containsKey(json, "id", DB_Communicator.JSON_TYPE_INT));
this.name = db.convertAndInitializeToString(db.containsKey(json, "name", DB_Communicator.JSON_TYPE_STRING));
this.email = db.convertAndInitializeToString(db.containsKey(json, "email", DB_Communicator.JSON_TYPE_STRING));
this.state = db.convertAndInitializeToString(db.containsKey(json, "state", DB_Communicator.JSON_TYPE_STRING));
this.setUserType(db.convertAndInitializeToString(db.containsKey(json, "userType", DB_Communicator.JSON_TYPE_STRING)));
this.listTeamRole = new List<VBTeamrole>();
if(json.ContainsKey("teamroles")) {
if(json["teamroles"] is JsonObject) {
JsonValue teamrole = json["teamroles"]["TeamRole"];
this.listTeamRole.Add(new VBTeamrole(teamrole));
} else {
foreach(JsonValue teamrole in json["teamroles"]) {
this.listTeamRole.Add(new VBTeamrole(teamrole["TeamRole"]));
}
}
}
}
示例12: valueOrDefault
public static JsonValue valueOrDefault(JsonValue jsonObject, string key, string defaultValue)
{
// Returns jsonObject[key] if it exists. If the key doesn't exist returns defaultValue and
// logs the anomaly into the Chronojump log.
if (jsonObject.ContainsKey (key)) {
return jsonObject [key];
} else {
LogB.Information ("JsonUtils::valueOrDefault: returning default (" + defaultValue + ") from JSON: " + jsonObject.ToString ());
return defaultValue;
}
}
示例13: toastJson
public void toastJson(Context context, JsonValue json, ToastLength length, string alternativeMessage) {
Context c = (context != null) ? context : mainActivity;
string message = (json.ContainsKey("message")) ? json["message"].ToString() : alternativeMessage;
Toast.MakeText(c, message, length).Show();
}
示例14: Populate
void Populate (JsonValue json, RootElement root, JsonValue data)
{
if (json.ContainsKey("title"))
root.Caption = json["title"];
JsonValue jsonRoot = null;
try {
jsonRoot = json["root"];
} catch (Exception){
Console.WriteLine("Bad JSON: could not find the root element - "+json.ToString()) ;
return;
}
foreach (JsonObject section in jsonRoot){
var sec = new Section(section.s("caption"), section.s("footer"));
if (section.ContainsKey("elements")){
foreach (JsonObject elem in section["elements"]) {
var dataForElement = data;
var bindExpression = elem.s("bind");
if (bindExpression!=null) {
try {
if (data!=null && data.JsonType==JsonType.Object){
var bind = elem.s("bind");
if (data != null && !string.IsNullOrEmpty(bind) && data.ContainsKey(bind)) {
dataForElement = data[bind];
}
} else if (bindExpression.StartsWith("#")) {
dataForElement = _controller.GetValue(bindExpression.Replace("#", ""));
}
} catch (Exception){
Console.WriteLine("Exception when binding element " + elem.ToString());
}
}
_parseElement(elem, sec, dataForElement);
}
} else if (section.ContainsKey("iterate") && data != null){
string iterationname = section["iterate"];
string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty";
var iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonArray)data : (JsonArray)data[iterationname];
var template = (JsonObject)section["template"];
var items = iterationdata.ToList();
if (items.Count>0) {
foreach(JsonValue v in items){
_parseElement(template, sec, v);
}
} else {
sec.Add(new EmptyListElement(emptyMessage));
}
} else if (section.ContainsKey("iterateproperties") && data != null){
string iterationname = section["iterateproperties"];
string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty";
var iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonObject)data : (JsonObject)data[iterationname];
var template = (JsonObject)section["template"];
var items = iterationdata.Keys;
if (items.Count>0) {
foreach(string v in items){
var obj = new JsonObject();
obj.Add(v, iterationdata[v]);
_parseElement(template, sec, obj);
}
} else {
sec.Add(new EmptyListElement(emptyMessage));
}
}
root.Add(sec);
}
}
示例15: containsKey
public JsonValue containsKey(JsonValue value, string key, int type) {
JsonPrimitive nullValue = new JsonPrimitive("");
switch(type) {
case JSON_TYPE_INT:
nullValue = new JsonPrimitive(0);
break;
case 1:
nullValue = new JsonPrimitive("");
break;
case 2:
nullValue = new JsonPrimitive(new DateTime());
break;
}
if(value == null)
return nullValue;
return (value.ContainsKey(key)) ? value[key] : nullValue;
}