get dictionary value by key

前端 未结 10 1939
逝去的感伤
逝去的感伤 2020-11-29 20:47

How can I get the dictionary value by key on function

my function code is this ( and the command what I try but didn\'t work ):

static void XML_Array         


        
10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 21:24

    I use a similar method to dasblinkenlight's in a function to return a single key value from a Cookie containing a JSON array loaded into a Dictionary as follows:

        /// 
        /// Gets a single key Value from a Json filled cookie with 'cookiename','key' 
        /// 
        public static string GetSpecialCookieKeyVal(string _CookieName, string _key)
        {
            //CALL COOKIE VALUES INTO DICTIONARY
            Dictionary dictCookie =
            JsonConvert.DeserializeObject>
             (MyCookinator.Get(_CookieName));
    
            string value;
            if (dictCookie.TryGetValue( _key, out value))
            {
                return value;
            }
            else
            {
                return "0";
            }
    
        }
    

    Where "MyCookinator.Get()" is another simple Cookie function getting an http cookie overall value.

提交回复
热议问题