本文整理汇总了C#中JsonObject.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.TryGetValue方法的具体用法?C# JsonObject.TryGetValue怎么用?C# JsonObject.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addMessage
//Add message to chat window.
void addMessage(JsonObject messge)
{
System.Object msg = null, fromName = null, targetName = null;
if (messge.TryGetValue("msg", out msg) && messge.TryGetValue("from", out fromName) &&
messge.TryGetValue("target", out targetName)) {
chatRecords.Add(new ChatRecord(fromName.ToString(), msg.ToString()));
}
}
示例2: InvokeCallBack
/// <summary>
/// Invoke the callback when the server return messge .
/// </summary>
/// <param name='pomeloMessage'>
/// Pomelo message.
/// </param>
public void InvokeCallBack(JsonObject msg)
{
if (msg != null) {
Action<JsonObject> action = null;
object id = null;
object body = null;
if (msg.TryGetValue("id", out id)){
if(this.callBackMap.TryGetValue(Convert.ToInt32(id), out action)) {
if (msg.TryGetValue("body", out body)) {
action.Invoke((JsonObject)SimpleJson.SimpleJson.DeserializeObject(body.ToString()));
}
}
}
}
}
示例3: PopulateFromJson
internal virtual JsonObject PopulateFromJson(JsonObject jsonObject)
{
IJsonValue value;
if (!jsonObject.TryGetValue("properties", out value))
return null;
var properties = value.GetObject();
if (properties == null)
return null;
if (properties.TryGetValue("additionalType", out value))
AdditionalType = value.GetString();
if (properties.TryGetValue("description", out value))
Description = value.GetString();
if (properties.TryGetValue("image", out value))
Image = value.GetString();
if (properties.TryGetValue("name", out value))
Name = value.GetString();
if (properties.TryGetValue("url", out value))
Url = value.GetString();
if (properties.TryGetValue("revision", out value))
Revision = (int)value.GetNumber();
if (properties.TryGetValue("extendedProperties", out value))
{
ExtendedProperties.Clear();
var fieldsObject = value.GetObject();
foreach (var field in fieldsObject)
{
ExtendedProperties.Add(field.Key, field.Value.GetString());
}
}
return properties;
}
示例4: FromJson
public static UserInteraction FromJson(JsonObject jsonObject)
{
IJsonValue value;
if (!jsonObject.TryGetValue("type", out value))
return null;
var userInteraction = new UserInteraction();
var index = Formats.IndexOf(value.GetString());
if (index != -1)
userInteraction.InteractionType = (UserInteractionType)index;
if (!jsonObject.TryGetValue("properties", out value))
return null;
var properties = value.GetObject();
if (properties == null)
return null;
if (properties.TryGetValue("description", out value))
userInteraction.Description = value.GetString();
if (properties.TryGetValue("commentText", out value))
userInteraction.CommentText = value.GetString();
if (properties.TryGetValue("commentTime", out value))
userInteraction.CommentTime = DateTimeHelper.FromString(value.GetString());
if (properties.TryGetValue("replyToUrl", out value))
userInteraction.ReplyToUrl = value.GetString();
if (properties.TryGetValue("creator", out value))
userInteraction.Creator = SchemaFactory.Parse(value.GetObject()) as IPerson;
return userInteraction;
}
示例5: NameValue
/// <summary>
/// Create obvject from JSON obkect
/// </summary>
/// <param name="oJsn">The JSON obkect</param>
public NameValue(JsonObject oJsn)
{
string name;
name = oJsn.Keys.ToArray<string>()[0];
IJsonValue val;
bool res = oJsn.TryGetValue(name, out val);
Name = name;
String Type = oJsn.GetNamedString("Type");
Value = val.ToString();
NameValues.Add(this);
}
示例6: FromJson
public static Review FromJson(JsonObject jsonObject)
{
IJsonValue value;
if (!jsonObject.TryGetValue("type", out value))
return null;
if (!jsonObject.TryGetValue("properties", out value))
return null;
var properties = value.GetObject();
if (properties == null)
return null;
var review = new Review();
if (properties.TryGetValue("name", out value))
review.Name = value.GetString();
if (properties.TryGetValue("url", out value))
review.Url = value.GetString();
if (properties.TryGetValue("description", out value))
review.Description = value.GetString();
if (properties.TryGetValue("datePublished", out value))
review.DatePublished = DateTimeHelper.FromString(value.GetString());
if (properties.TryGetValue("reviewBody", out value))
review.ReviewBody = value.GetString();
if (properties.TryGetValue("author", out value))
review.Author = SchemaFactory.Parse(value.GetObject()) as IPerson;
if (properties.TryGetValue("itemReviewed", out value))
review.ItemReviewed = SchemaFactory.Parse(value.GetObject());
if (properties.TryGetValue("reviewRating", out value))
review.ReviewRating = Rating.FromJson(value.GetObject());
if (properties.TryGetValue("aggregateRating", out value))
review.AggregateRating = AggregateRating.FromJson(value.GetObject());
return review;
}
示例7: Parse
internal static IThing Parse(JsonObject json)
{
if (json == null)
return null;
IJsonValue value;
if (!json.TryGetValue("type", out value))
return null;
var thing = Create(value.GetString()) as Thing;
if (thing != null)
thing.PopulateFromJson(json);
return thing;
}
示例8: FromJson
public static Rating FromJson(JsonObject jsonObject)
{
IJsonValue value;
if (!jsonObject.TryGetValue("type", out value) || !value.GetString().Equals(Schema.Rating) )
return null;
var properties = value.GetObject();
if (properties == null)
return null;
var rating = new Rating();
if (properties.TryGetValue("bestRating", out value))
rating.BestRating = (int)value.GetNumber();
if (properties.TryGetValue("ratingValue", out value))
rating.RatingValue = (int)value.GetNumber();
if (properties.TryGetValue("worstRating", out value))
rating.WorstRating = (int)value.GetNumber();
return rating;
}
示例9: decodeObject
//Decode the user-defined object type in message.
private JsonObject decodeObject(string type, JsonObject proto)
{
if (proto != null) {
object __messages;
if (proto.TryGetValue("__messages", out __messages)) {
object _type;
if (((JsonObject)__messages).TryGetValue(type, out _type) || protos.TryGetValue("message " + type, out _type)) {
int l = (int)Decoder.decodeUInt32(this.getBytes());
JsonObject msg = new JsonObject();
return this.decodeMsg(msg, (JsonObject)_type, this.offset + l);
}
}
}
return new JsonObject();
}
示例10: TryParseFeature
private bool TryParseFeature(JsonObject obj, out object result)
{
string typeString;
if(TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant()== "feature")
{
object geometry;
object geo;
if (obj.TryGetValue("geometry", out geometry) && TryParseGeometry((JsonObject)geometry, out geo))
{
object prop;
Dictionary<string, object> pr = null;
if (obj.TryGetValue("properties", out prop) && prop is JsonObject)
{
var props = (JsonObject) prop;
if (props.Count > 0)
{
pr = props.ToDictionary(x => x.Key, x=> SantizeJsonObjects(x.Value));
}
}
result = new Feature((IGeoJsonGeometry)geo, pr);
object id;
if (obj.TryGetValue("id", out id))
{
((Feature) result).Id = SantizeJsonObjects(id);
}
return true;
}
}
result = null;
return false;
}
示例11: TryGetValueTest
public void TryGetValueTest()
{
string key1 = AnyInstance.AnyString;
string key2 = AnyInstance.AnyString2;
JsonValue value1 = AnyInstance.AnyJsonValue1;
JsonValue value2 = AnyInstance.AnyJsonValue2;
JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } };
JsonValue value;
Assert.True(target.TryGetValue(key2, out value));
Assert.Equal(value2, value);
Assert.False(target.TryGetValue("not a key", out value));
Assert.Null(value);
}
示例12: decodeMsg
/// <summary>
/// Decode the message.
/// </summary>
/// <returns>
/// The message.
/// </returns>
/// <param name='msg'>
/// JsonObject.
/// </param>
/// <param name='proto'>
/// JsonObject.
/// </param>
/// <param name='length'>
/// int.
/// </param>
private JsonObject decodeMsg(JsonObject msg, JsonObject proto, int length)
{
while(this.offset < length) {
Dictionary<string, int> head = this.getHead();
int tag;
if (head.TryGetValue("tag", out tag)) {
object _tags = null;
if (proto.TryGetValue("__tags", out _tags)){
object name;
if(((JsonObject)_tags).TryGetValue(tag.ToString(), out name)) {
object value;
if(proto.TryGetValue(name.ToString(), out value)) {
object option;
if (((JsonObject)(value)).TryGetValue("option", out option)) {
switch(option.ToString()){
case "optional":
case "required":
object type;
if (((JsonObject)(value)).TryGetValue("type", out type)) {
msg.Add(name.ToString(), this.decodeProp(type.ToString(), proto));
}
break;
case "repeated":
object _name;
if (!msg.TryGetValue(name.ToString(), out _name)) {
msg.Add(name.ToString(), new List<object>());
}
object value_type;
if (msg.TryGetValue(name.ToString(), out _name) && ((JsonObject)(value)).TryGetValue("type", out value_type)) {
decodeArray((List<object>)_name, value_type.ToString(), proto);
}
break;
}
}
}
}
}
}
}
return msg;
}
示例13: CreateTimeSlot
private static TimeSlot CreateTimeSlot(JsonObject obj)
{
TimeSlot slot = new TimeSlot();
foreach (var key in obj.Keys)
{
IJsonValue val;
if (!obj.TryGetValue(key, out val))
continue;
switch (key)
{
case "ID":
slot.ID = (int)val.GetNumber();
break;
case "Stage":
JsonObject stageTimeSlot = val.GetObject();
Stage stage = null;
IJsonValue stageID;
if (!stageTimeSlot.TryGetValue("ID", out stageID))
continue;
int sID = (int)stageID.GetNumber();
foreach (var s in _dataSource.Stages)
{
if (s.ID == sID)
stage = s;
}
if (stage == null)
stage = CreateStage(stageTimeSlot);
slot.Stage = stage;
break;
case "StartDate":
slot.StartDate = JsonToDateTime(val);
break;
case "EndDate":
slot.EndDate = JsonToDateTime(val);
break;
}
}
// Update the timeslots in the stages
if (slot.Stage != null)
{
if (slot.Stage.TimeSlots == null)
slot.Stage.TimeSlots = new ObservableCollection<TimeSlot>();
slot.Stage.TimeSlots.Add(slot);
}
_dataSource.TimeSlots.Add(slot);
return slot;
}
示例14: CreateGenre
private static Genre CreateGenre(JsonObject obj)
{
Genre genre = new Genre();
foreach (var key in obj.Keys)
{
IJsonValue val;
if (!obj.TryGetValue(key, out val))
continue;
switch (key)
{
case "ID":
genre.ID = (int)val.GetNumber();
break;
case "Name":
genre.Name = val.GetString();
break;
}
}
_dataSource.Genres.Add(genre);
return genre;
}
示例15: CreateStage
private static Stage CreateStage(JsonObject obj)
{
Stage stage = new Stage();
foreach (var key in obj.Keys)
{
IJsonValue val;
if (!obj.TryGetValue(key, out val))
continue;
switch (key)
{
case "ID":
stage.ID = (int)val.GetNumber();
break;
case "Name":
stage.Name = val.GetString();
break;
}
}
_dataSource.Stages.Add(stage);
return stage;
}