0

Hi I am new to jquery

var sales = [{CategoryName="colddrink",ProductName="coke", SaleMonth="Feb ",    CategoryId=1},
{ CategoryName="colddrink",ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1}     {CategoryName="Snacks", ProductName="nuts",SaleMonth="Dec", CategoryId=32},
         {CategoryName="colddrink",ProductName="pepsi", SaleMonth="Mar ", CategoryId=1},
         {CategoryName="Snacks",ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]

and that is what I am looking for

var sales = { "colddrink" :[{ProductName="coke", SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi", SaleMonth="Mar ", CategoryId=1}],

    "Snacks"  :[{ProductName="nuts",SaleMonth="Dec", CategoryId=32},
            {ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]
    }

Is it possible in jquery?

Alex R.
  • 4,664
  • 4
  • 30
  • 40
Abhishek
  • 173
  • 1
  • 2
  • 6
  • 1
    This is not JSON. This is Object Literal syntax; see http://stackoverflow.com/questions/8294088/javascript-object-vs-json – Matt Feb 21 '12 at 09:27

2 Answers2

1

Nested objects?

var sales = {
    cooldrink : {
        productname: 'coke',
        salemonth: 'feb'
    },
    snacks: {
        productname: 'nuts',
        salemonth: 'dec'
    }
};

alert(sales.cooldrink.productname);​ //coke
Johan
  • 35,120
  • 54
  • 178
  • 293
0

It's not really jQuery, though jQuery use JSON most of the time, but this one is simply JSON, an object in Javascript. Just create a function which can sort things out. In fact, you don't need any jQuery at all for this type of job.

Ronald Borla
  • 586
  • 4
  • 19
  • 1
    There are important differences between JSON and JavaScript objects (namely Object literal syntax); http://stackoverflow.com/questions/8294088/javascript-object-vs-json – Matt Feb 21 '12 at 09:30