本文整理汇总了C#中JsonObject.GetNamedValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.GetNamedValue方法的具体用法?C# JsonObject.GetNamedValue怎么用?C# JsonObject.GetNamedValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.GetNamedValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Optional
public static int Optional(JsonObject jsonObject, string name, int defaultValue = 0)
{
int val = defaultValue;
try
{
if (jsonObject.ContainsKey(name))
val = (int)jsonObject.GetNamedValue(name).GetNumber();
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("JsonHelper.Optional(): " + e.Message);
}
return val;
}
示例2: OptionalString
public static string OptionalString(JsonObject jsonObject, string name, string defaultValue = "")
{
string val = defaultValue;
try
{
if(jsonObject.ContainsKey(name))
val = (string)jsonObject.GetNamedValue(name).GetString();
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("JsonHelper.OptionalString(): " + e.Message);
}
return val;
}
示例3: OptionalObject
public static JsonObject OptionalObject(JsonObject jsonObject, string name)
{
JsonObject val = null;
try
{
if (jsonObject.ContainsKey(name))
if(jsonObject.GetNamedValue(name).ValueType == JsonValueType.Object)
val = jsonObject.GetNamedObject(name);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("JsonHelper.OptionalObject(): " + e.Message);
}
return val;
}
示例4: onTaskCompleted
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode)
{
if (result != null)
{
if (requestCode == APIRequest.requestCodeType.Share)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
Name = json.GetNamedString("name");
Value = json.GetNamedNumber("value");
Time = json.GetNamedString("time");
Date = json.GetNamedString("date");
if (json.GetNamedValue("limit_down").ValueType != JsonValueType.Null)
LimitDown = json.GetNamedNumber("limit_down");
else
LimitDown = null;
if (json.GetNamedValue("limit_up").ValueType != JsonValueType.Null)
LimitUp = json.GetNamedNumber("limit_up");
else
LimitUp = null;
Favorite = Convert.ToBoolean(json.GetNamedNumber("is_main"));
}
else
{
if (NavigatePortfolio != null)
NavigatePortfolio();
}
}
else if (requestCode == APIRequest.requestCodeType.ShareEvolution)
{
ValuesEvolution.Clear();
Values2Evolution.Clear();
JsonArray json = JsonArray.Parse(result);
//var i = 0;
foreach (var point in json)
{
//i++;
JsonObject jsonPoint = JsonObject.Parse(point.Stringify());
string date = jsonPoint.GetNamedString("date");
//date = date.Substring(5, date.Length - 5);
double high = jsonPoint.GetNamedNumber("high");
double low = jsonPoint.GetNamedNumber("low");
var split = date.Split('-');
DateTime date2 = new DateTime(Int32.Parse(split[0]), Int32.Parse(split[1]), Int32.Parse(split[2]));
ValuesEvolution.Add(new Tuple<DateTime, double>(date2, low));
Values2Evolution.Add(new Tuple<DateTime, double>(date2, high));
}
}
else if (requestCode == APIRequest.requestCodeType.Favorite)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
Favorite = true;
}
}
else if (requestCode == APIRequest.requestCodeType.Unfavorite)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
Favorite = false;
}
}
else if (requestCode == APIRequest.requestCodeType.ClearLimitUp)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
LimitUp = null;
}
}
else if (requestCode == APIRequest.requestCodeType.ClearLimitDown)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
LimitDown = null;
}
}else if (requestCode == APIRequest.requestCodeType.PortfolioRemove)
{
JsonObject json = new JsonObject();
JsonObject.TryParse(result, out json);
if (!json.ContainsKey("error"))
{
if (NavigatePortfolio != null)
NavigatePortfolio();
}
//.........这里部分代码省略.........
示例5: HandleMessage
protected void HandleMessage(JsonObject message)
{
try
{
var shouldProcess = true;
if (Listener != null)
shouldProcess = Listener.OnReceiveMessage(message);
if (!shouldProcess)
return;
var type = message.GetNamedString("type");
Object payload = 1;
try
{
payload = message.GetNamedObject("payload");
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// we will fail when the type is error because payload is not retrievable
}
ServiceCommand request = null;
int id = 0;
if (message.ContainsKey("id"))
{
if (message.ContainsKey("id"))
{
if (message.GetNamedValue("id").ValueType != JsonValueType.String)
{
id = (int)message.GetNamedNumber("id");
}
else
{
var intstr = message.GetNamedString("id");
int.TryParse(intstr, out id);
}
}
try
{
if (Requests.ContainsKey(id))
request = Requests[id];
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// since request is assigned to null, don't need to do anything here
}
}
if (type.Length == 0)
return;
if ("response".Equals(type))
{
if (request != null)
{
Logger.Current.AddMessage("Found requests. Need to handle response.");
if (payload != null)
{
try
{
Util.PostSuccess(request.ResponseListenerValue, payload);
}
catch
{
}
}
else
{
try
{
Util.PostError(request.ResponseListenerValue,
new ServiceCommandError(-1, "JSON parse error"));
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
}
}
if (!(request is UrlServiceSubscription))
{
if (!message.ContainsKey("pairingType"))
{
Requests.Remove(id);
}
}
}
}
else if ("registered".Equals(type))
{
if (!(service.ServiceConfig is WebOsTvServiceConfig))
{
service.ServiceConfig = new WebOsTvServiceConfig(service.ServiceConfig.ServiceUuid);
//.........这里部分代码省略.........
示例6: AssignSpecificDetails
private static void AssignSpecificDetails(PBCCourse course, JsonObject courseObject)
{
if (courseObject.GetNamedValue("project_title").ValueType != JsonValueType.Null)
course.ProjectTitle = courseObject.GetNamedString("project_title");
else
course.ProjectTitle = null;
}