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


C# JsonObject.ContainsKey方法代码示例

本文整理汇总了C#中JsonObject.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.ContainsKey方法的具体用法?C# JsonObject.ContainsKey怎么用?C# JsonObject.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonObject的用法示例。


在下文中一共展示了JsonObject.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTest

        public void AddTest()
        {
            string key1 = AnyInstance.AnyString;
            string key2 = AnyInstance.AnyString2;
            JsonValue value1 = AnyInstance.AnyJsonValue1;
            JsonValue value2 = AnyInstance.AnyJsonValue2;

            JsonObject target;

            target = new JsonObject();
            target.Add(new KeyValuePair<string, JsonValue>(key1, value1));
            Assert.Equal(1, target.Count);
            Assert.True(target.ContainsKey(key1));
            Assert.Equal(value1, target[key1]);

            target.Add(key2, value2);
            Assert.Equal(2, target.Count);
            Assert.True(target.ContainsKey(key2));
            Assert.Equal(value2, target[key2]);

            ExceptionHelper.Throws<ArgumentNullException>(delegate { new JsonObject().Add(null, value1); });
            ExceptionHelper.Throws<ArgumentNullException>(delegate { new JsonObject().Add(new KeyValuePair<string, JsonValue>(null, value1)); });

            ExceptionHelper.Throws<ArgumentException>(delegate { new JsonObject().Add(key1, AnyInstance.DefaultJsonValue); });
            ExceptionHelper.Throws<ArgumentException>(delegate { new JsonArray().Add(AnyInstance.DefaultJsonValue); });
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:26,代码来源:JsonObjectTest.cs

示例2: TaskData

    public TaskData(JsonObject o)
    {
        count = Convert.ToInt32(o ["count"]);
        killCount = Convert.ToInt32(o ["killCount"]);
        createTime = (long)Convert.ToInt64(o ["createtime"]);
        prizedTime = (long)Convert.ToInt64(o["finishtime"]);
        templateID = Convert.ToInt32(o ["tid"]);
        status = (TaskStatus)Convert.ToInt32(o ["status"]);       
        if (o.ContainsKey("buyCount"))
        {
            buyCount = Convert.ToInt32(o ["buyCount"]);
        }

        if (o.ContainsKey("buyTime"))
        {
            buyTime = (long)Convert.ToInt64(o ["buyTime"]);
        }

        taskType = (TaskMechanism)Convert.ToInt32(o ["taskType"]);

        if (o.ContainsKey("starLevel"))
        {
            starLevel = Convert.ToInt32(o["starLevel"]);
        }
    }
开发者ID:xiaozhuzhaoge,项目名称:Universal-Space,代码行数:25,代码来源:TaskData.cs

示例3: getJsonData

 public static object getJsonData(JsonObject jo, string key)
 {
     if (jo.ContainsKey(key))
         return jo[key];
     else
         return null;
 }
开发者ID:RyuaNerin,项目名称:ExHentaiAPI,代码行数:7,代码来源:Helper.cs

示例4: _CheckData

        private static bool _CheckData(JsonObject obj)
        {
            bool ret = false;
            if (false == obj.ContainsKey(mCnstChkHeader)
                || mCnstChkHeaderData != obj[mCnstChkHeader].GetString()
                || false == obj.ContainsKey(mCnstChkBody))
            {
                ret = false;
            }
            else
            {
                ret = true;
            }

            return ret;
        }
开发者ID:jingwang109,项目名称:mobile-sdk,代码行数:16,代码来源:AlipaySdk.cs

示例5: FromJson

        internal static SmMapServiceInfo FromJson(JsonObject json)
        {
            if (json == null) return null;

            if (!json.ContainsKey("name") || !json.ContainsKey("bounds")) return null;

            return new SmMapServiceInfo
            {
                ViewBounds = JsonHelper.ToRectangle2D(json["viewBounds"].GetObjectEx()),
                CoordUnit = (Unit)Enum.Parse(typeof(Unit), json["coordUnit"].GetStringEx(), true),
                Bounds = JsonHelper.ToRectangle2D(json["bounds"].GetObjectEx()),
                PrjCoordSys = PrjCoordSys.FromJson(json["prjCoordSys"].GetObjectEx()),
                Scale = json["scale"].GetNumberEx(),
                Viewer = JsonHelper.ToRect(json["viewer"].GetObjectEx())
            };
        }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:16,代码来源:SmMapServiceInfo.cs

示例6: GetJosnObjectStringValue

        internal static string GetJosnObjectStringValue(JsonObject jsonObject, string key)
        {
            string reValue = "";
            if ((jsonObject == null) || string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                return reValue;
            }

            if (jsonObject.ContainsKey(key))
            {
                string value = jsonObject.GetNamedString(key); ;
                if ((string.IsNullOrEmpty(value)) || (value.Equals("null")))
                {
                    return reValue;
                }
                else
                {
                    value.TrimStart();
                    value.TrimEnd();

                    reValue = value;
                }
            }
            return reValue;
        }
开发者ID:RaulVan,项目名称:Recommender,代码行数:25,代码来源:Helpers.cs

示例7: FromJson

 internal static JoinItem FromJson(JsonObject json)
 {
     if (json == null) return null;
     JoinItem item = new JoinItem();
     if (json.ContainsKey("foreignTableName"))
     {
         item.ForeignTableName = json["foreignTableName"].GetStringEx();
     }
     if (json.ContainsKey("joinFilter"))
     {
         item.JoinFilter = json["joinFilter"].GetStringEx();
     }
     if (json.ContainsKey("joinType") && !string.IsNullOrEmpty(json["joinType"].GetStringEx()))
     {
         item.JoinType = (JoinType)Enum.Parse(typeof(JoinType), json["joinType"].GetStringEx(), true);
     }
     return item;
 }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:18,代码来源:JoinItem.cs

示例8: ParseRawChannelData

        public static ChannelInfo ParseRawChannelData(JsonObject channelRawData)
        {
            string channelName = null;
            string channelId = null;
            var minorNumber = 0;
            var majorNumber = 0;

            var channelInfo = new ChannelInfo {RawData = channelRawData};

            try
            {
                if (!channelRawData.ContainsKey("channelName"))
                    channelName = channelRawData.GetNamedString("channelName");

                if (!channelRawData.ContainsKey("channelId"))
                    channelId = channelRawData.GetNamedString("channelId");

                if (!channelRawData.ContainsKey("majorNumber"))
                    majorNumber = (int)channelRawData.GetNamedNumber("majorNumber");

                if (!channelRawData.ContainsKey("minorNumber"))
                    minorNumber = (int)channelRawData.GetNamedNumber("minorNumber");

                var channelNumber = !channelRawData.ContainsKey("channelNumber")
                    ? channelRawData.GetNamedString("channelNumber")
                    : string.Format("{0}-{1}", majorNumber, minorNumber);

                channelInfo.Name = channelName;
                channelInfo.Id = channelId;
                channelInfo.Number = channelNumber;
                channelInfo.MajorNumber = majorNumber;
                channelInfo.MinorNumber = minorNumber;

            }
            catch (Exception e)
            {
                //TODO: get some analysis here
                throw new Exception("There was an error parsin the channel information", e);
            }

            return channelInfo;
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:42,代码来源:NetcastChannelParser.cs

示例9: FromJson

        internal static LabelThemeCell FromJson(JsonObject json)
        {
            if (json == null) return null;

            LabelThemeCell themeCell = new LabelThemeCell();
            themeCell.ThemeLabel = ThemeLabel.FromJson(json);
            if (json.ContainsKey("type") && json["type"] != null)
            {
                themeCell.Type = (LabelMatrixCellType)Enum.Parse(typeof(LabelMatrixCellType), json["type"].GetStringEx(), true);
            }
            return themeCell;
        }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:12,代码来源:LabelThemeCell.cs

示例10: checkMsg

        /// <summary>
        /// Check the message.
        /// </summary>
        private bool checkMsg(JsonObject msg, JsonObject proto)
        {
            ICollection<string> protoKeys = proto.Keys;
            foreach(string key in protoKeys) {
                JsonObject value = (JsonObject)proto[key];
                object proto_option;
                if (value.TryGetValue("option", out proto_option)) {
                    switch(proto_option.ToString()) {
                        case "required":
                            if(!msg.ContainsKey(key)) {
                                return false;
                            }else{

                            }
                            break;
                        case "optional":
                            object value_type;

                            JsonObject messages = (JsonObject)proto["__messages"];

                            value_type = value["type"];

                            if(msg.ContainsKey(key)){
                                Object value_proto;

                                if(messages.TryGetValue(value_type.ToString(), out value_proto) || protos.TryGetValue("message " + value_type.ToString(), out value_proto)){
                                    checkMsg ((JsonObject)msg[key], (JsonObject)value_proto);
                                }
                            }
                            break;
                        case "repeated":
                            object msg_name;
                            object msg_type;
                            if (value.TryGetValue("type", out value_type) && msg.TryGetValue(key, out msg_name)) {
                            if(((JsonObject)proto["__messages"]).TryGetValue(value_type.ToString(), out msg_type) || protos.TryGetValue("message " + value_type.ToString(), out msg_type)){
                                    List<object> o = (List<object>)msg_name;
                                    foreach(object item in o) {
                                        if (!checkMsg((JsonObject)item, (JsonObject)msg_type)) {
                                            return false;
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }
            }
            return true;
        }
开发者ID:koalaylj,项目名称:pomelo-client-proto-test,代码行数:52,代码来源:MsgEncoder.cs

示例11: GalleryInfo

        internal GalleryInfo(JsonObject jo)
        {
            int i;
            float f;

            this.token = new GalleryToken((int)jo["gid"], (string)jo["token"]);

            this.error = (string)jo["error"];
            this.ArchiverKey = (string)jo["archiver_key"];
            this.ArchiverKeyTime = DateTime.Now.AddHours(1);
            this.ArchiverKeyTimeUTC = DateTime.UtcNow.AddHours(1);
            this.Title = (string)jo["title"];
            this.TitleJpn = (string)jo["title_jpn"];
            this.ThumbURL = (string)jo["thumb"];
            this.Uploader = (string)jo["uploader"];
            this.Expunged = (bool)jo["expunged"];
            this.FileSize = (int)jo["filesize"];

            if (int.TryParse((string)jo["torrentcount"], out i))
                this.TorrentCount = i;
            else
                this.TorrentCount = 0;

            if (int.TryParse((string)jo["posted"], out i))
            {
                this.PostedUTC = Helper.ToDateTime(i);
                this.Posted = this.PostedUTC.ToLocalTime();
            }

            if (int.TryParse((string)jo["filecount"], out i))
                this.FileCount = i;
            else
                this.FileCount = 0;

            if (float.TryParse((string)jo["rating"], out f))
                this.Rating = f;
            else
                this.Rating = 0;

            this.Category = Helper.ToCategories((string)jo["category"]);

            if (jo.ContainsKey("tags"))
            {
                JsonArray ja = (JsonArray)jo["tags"];
                this.Tags = new string[ja.Count];
                for (i = 0; i < ja.Count; i++)
                    this.Tags[i] = (string)ja[i];
            }
        }
开发者ID:RyuaNerin,项目名称:ExHentaiAPI,代码行数:49,代码来源:GalleryInfo.cs

示例12: GetJosnObjectIntegerValue

        internal static string GetJosnObjectIntegerValue(JsonObject jsonObject, string key)
        {
            string reValue = "";
            if ((jsonObject == null) || string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                return reValue;
            }

            if (jsonObject.ContainsKey(key))
            {
                double value = jsonObject.GetNamedNumber(key);
                reValue = Convert.ToString((int)value);
            }
            return reValue;
        }
开发者ID:RaulVan,项目名称:Recommender,代码行数:15,代码来源:Helpers.cs

示例13: 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;
        }
开发者ID:WombatWorks,项目名称:windows10-sdk,代码行数:16,代码来源:JsonHelper.cs

示例14: 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;
        }
开发者ID:WombatWorks,项目名称:windows10-sdk,代码行数:16,代码来源:JsonHelper.cs

示例15: FromJson

        internal static LabelSymbolCell FromJson(JsonObject json)
        {
            if (json == null) return null;
            LabelSymbolCell symbolCell = new LabelSymbolCell();
            if (json["style"] != null)
            {
                symbolCell.Style = ServerStyle.FromJson(json["style"].GetObjectEx());
            }
            symbolCell.SymbolIDField = json["symbolIDField"].GetStringEx();

            if (json.ContainsKey("type") && json["type"] != null)
            {
                symbolCell.Type = (LabelMatrixCellType)Enum.Parse(typeof(LabelMatrixCellType), json["type"].GetStringEx(), true);
            }

            return symbolCell;
        }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:17,代码来源:LabelSymbolCell.cs


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