Ajay Krishna Dutta
Ajay Krishna Dutta

Reputation: 772

Json responsed data not display

I have a json response string as follows:

[
  {
    "0":
        {
          "total":"2.00"
        },
    "PaymentCollection":
        {
          "emp_id":"E0004"
        }
  }
]

and my jQuery function is

$.each(resp,function(indx,obj){
    alert(obj.0.total);
}); 

Unfortunately the alert is not working.. please help

Upvotes: 1

Views: 48

Answers (2)

Magus
Magus

Reputation: 15104

.0 is not valid in javascript (an identifier can't start with a digit). You can use the "array notation" : alert(obj["0"].total);

Upvotes: 1

Manwal
Manwal

Reputation: 23816

You can access like this:

obj['0'].total

or

obj['0']['total']

DEMO

Upvotes: 1

Related Questions