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 7665683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:38:11+00:00 2026-05-31T14:38:11+00:00

I’m trying to build a shopping cart. There’s very simple class which creates a

  • 0

I’m trying to build a shopping cart.

There’s very simple class which creates a generic.dictionary(of string, generic.dictionary(of string, string) this contains my cart items.

The keys for the intitial dictionary are the item Ids, so I can easily check whether the item is already in the cart using cartDictionary.ContainsKey(id) and then increment the quantity or add a new as required.

The BUY button triggers and AJAX-ified web method, which returns data looking like this:

{
    "d": {
        "7907": {
            "id": "7907",
            "qty": "4",
            "singlePrice": "1185"
        },
        "2698": {
            "id": "2698",
            "qty": "1",
            "singlePrice": "1322"
        }
    }
}

The initial item d is created automatically by the AJAX post for reasons which I dont understand, but it doesnt really matter, my output is therefore data.d in my AJAX success, as follows:

success: function (data) {
    result = [data.d];
}

Now, from this I need to be able to get the inner data to present it into a shopping cart

So I need to be able to loop through the items by ID and extract

id
qty
singlePrice

So that I can display it in the browser, but I’m going cross eyed trying to work it out.

I’ve tried adding [ around data.d, like

var result = [data.d]

and tried looping within the result like

result = [data.d];

    $(result).each(function (i, thing) {
         var thisOne = (result[i]);
         //alert(thing); //<< returns object object
         $(thisOne).each(function (j, val) {
              alert(thisOne + " - " + val.id); //<< both thisOne and val.id return object object
         });
     });

By the returns from the alerts I am clearing getting some kind of JSON objects, but I’ve obviously got something mixed up!

I’m no programmer, but working on a project which is slowly driving me crazy!!

  • 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-31T14:38:12+00:00Added an answer on May 31, 2026 at 2:38 pm

    You should do

    var data = {
        "d": {
            "7907": {
                "id": "7907",
                "qty": "4",
                "singlePrice": "1185"
            },
            "2698": {
                "id": "2698",
                "qty": "1",
                "singlePrice": "1322"
            }
        }
    }
    
    
    
    var result = data.d;
    
    $.each(result , function(ind, el) {
        //alert(thing); //<< returns object object
        alert(ind + " - " + el.id);
    });
    

    fiddle here http://jsfiddle.net/VHPQX/

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.