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

  • SEARCH
  • Home
  • 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 3497504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:22:43+00:00 2026-05-18T12:22:43+00:00

This will work : var json = { ‘items’: [{ ‘id’: 72, ‘quantity’: 1,

  • 0

This will work :

var json = { 'items': [{ 'id': 72, 'quantity': 1, 'format': '90ml' }, { 'id': 72, 'quantity': 4, 'format': '70ml'}] }
alert(json.items[1].id);

This will NOT work :

var json = $.cookie('json_string');
alert(json.items[1].id);

the json_string in the cookie is EXACTLY the same as in example #1. After fooling around, I realized I need to do this to make it work:

    eval("var json = " + $.cookie("json_cart"));

Is this the correct way to do it? It seems like a hack, im facing some challenges when trying to make this javascript / c# json communication, i tought it would be very easy. Anyway. At least I got it running now.

  • 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-05-18T12:22:43+00:00Added an answer on May 18, 2026 at 12:22 pm

    This is NORMAL

    • In your first case, you are using an object literal.
    • In the second case, this is a string containing data formatted using the JSON data-interchange format.

    To de-serialize the string to an object, and assuming you target modern browsers, you could use the native function to do:

    var myObj = JSON.parse($.cookie('json_string'));
    

    Or you could import json2.js from the official JSON website and use the same line as above.

    Or, as mentioned by subhaze, you can be completely jQuery-y and use:

    var myObj = jQuery.parseJSON('{"name":"John"}');
    

    A Note About URL-Encoding

    If the string is encoded in the cookie, then you need to decode it first, using decodeURIComponent() like this:

    var myObj = JSON.parse(decodeURIComponent($.cookie('json_string')))
    

    A Note About Quoted Keys

    Your JSON is actually invalid, as it requires double-quoted keys. You should use double-quotes (") to wrap around your keys and your string values.

    Check It

    To quickly check for the validity of your JSON, try JSONLint.


    Your question is very similar to others. So, in the future, be sure to check for similar questions first by checking the JSON tag or searching for your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If the following works: alert( data.query.results.tbody[1].tr[0].td[0].span.img.src ); Why will this not work? var image
Will this work for testing whether a value at position index exists or not,
I am unsure why this code will not work. When I click a button
ATM i cant quiet imagine how this will work. I'm sure it can be
What do I have to do so that this will work in the console
How can i make an extension method that will work like this public static
Is there a reason why this query doesn't work? The following query will work
I guess my main question is, will this always work as long as I
I have the this code that will create excel file and work sheet then
I have this code below. I randomly ran across that it will work if

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.