当前位置: 首页>>代码示例>>C#>>正文


C# JsonObject.TryGetValue方法代码示例

本文整理汇总了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()));
         }
 }
开发者ID:NetEase,项目名称:pomelo-unitychat,代码行数:9,代码来源:ChatGUI.cs

示例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()));
                 }
             }
         }
     }
 }
开发者ID:AlfHub,项目名称:pomelo-unityclient,代码行数:21,代码来源:EventManager.cs

示例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;
        }
开发者ID:AndreiMarukovich,项目名称:Transhipment,代码行数:35,代码来源:Thing.cs

示例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;
        }
开发者ID:AndreiMarukovich,项目名称:Transhipment,代码行数:31,代码来源:UserInteraction.cs

示例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);
        }
开发者ID:djaus2,项目名称:IoTSysInfo,代码行数:16,代码来源:SysInfo.cs

示例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;
        }
开发者ID:AndreiMarukovich,项目名称:Transhipment,代码行数:37,代码来源:Review.cs

示例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;
        }
开发者ID:AndreiMarukovich,项目名称:Transhipment,代码行数:15,代码来源:SchemaFactory.cs

示例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;
        }
开发者ID:AndreiMarukovich,项目名称:Transhipment,代码行数:20,代码来源:Rating.cs

示例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();
 }
开发者ID:koalaylj,项目名称:pomelo-client-proto-test,代码行数:16,代码来源:MsgDecoder.cs

示例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;
        }
开发者ID:spadger,项目名称:Geo,代码行数:34,代码来源:GeoJsonReader.cs

示例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);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:16,代码来源:JsonObjectTest.cs

示例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;
 }
开发者ID:koalaylj,项目名称:pomelo-client-proto-test,代码行数:56,代码来源:MsgDecoder.cs

示例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;
        }
开发者ID:Kefke,项目名称:FestivalAdministration,代码行数:55,代码来源:DataSource.cs

示例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;
        }
开发者ID:Kefke,项目名称:FestivalAdministration,代码行数:24,代码来源:DataSource.cs

示例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;
        }
开发者ID:Kefke,项目名称:FestivalAdministration,代码行数:24,代码来源:DataSource.cs


注:本文中的JsonObject.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。