Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:32:24+00:00 2026-06-02T20:32:24+00:00

I used JSON.stringify() to store a javascript associative array of integer keys with boolean

  • 0

I used JSON.stringify() to store a javascript associative array of integer keys with boolean values in a cookie e.g. var arr = {}; arr[9000001] = True;. I can see the value of the string on the server in the following format: %7B%229000001%22%3Atrue%2C%229000003%22%3Atrue%2C%229000006%22%3Atrue%2C%229000009%22%3Atrue%7D where the first number is 9000001, second is 9000003, and so on.

I would like to use Json.Net to deserialize into a Dictionary<long,bool> or similar. I try the following

var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(cookieValue);

but get the following exception

{"Unexpected character encountered while parsing value: %. Path '', line 0, position 0."}

I’m guessing deserialization is not possible in this scenario?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:32:26+00:00Added an answer on June 2, 2026 at 8:32 pm

    Frits van Campen found the missing piece. I wrote the following extension method that makes it easy to retrieve cookie values in C#. Set both urlDecode and fromJson to true and the object will be successfully deserialized.

    /// <summary>
    /// retrieve object from cookie
    /// </summary>
    /// <typeparam name="T">type of object</typeparam>
    /// <param name="controller"></param>
    /// <param name="cookieName">name of cookie</param>
    /// <param name="urlDecode">true to enable url decoding of the string</param>
    /// <param name="fromJson">true if the string in cookie is Json stringified</param>
    /// <returns>object in the cookie, or default value of T if object does not exist</returns>
    public static T GetFromCookie<T>(this Controller controller, string cookieName, 
                                     bool urlDecode = true, bool fromJson = false)
    {
        var cookie = controller.HttpContext.Request.Cookies[cookieName];
        if (cookie == null) return default(T);
        var value = cookie.Value;
    
        if (urlDecode)
            value = Uri.UnescapeDataString(value);
    
        T result;
        if (fromJson)
            result = JsonConvert.DeserializeObject<T>(value);
        else
            result = (T)Convert.ChangeType(value, typeof(T));
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment used: ASP.NET, jQuery I have the following AJAX call: var tempVar = JSON.stringify({plotID:currentId});
I have gathered data with jQuery, putten it into a multidimensional array, used JSON.stringify
I have a JSON data store used for a combobox selection which is working
I have used JSON::Any in my program to transfer the hash between client and
I have created one application in j2me, I have used json parsing in that
I am having an issue dealing with the notation used in a JSON file
I am new to JSON programming in J2ME. I discovered that Json is used
I used to have this kind of simple JSON data and I could successfully
I created a php file to return data encoded with JSON and then used
i have something similar to the following... used a python script to JSON to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.