1

I have some strange porblem with jQuery. From a web socket I get the following JSON string:

{
  "time" : 1373772581860,
  "entries" : {
    "OK" : 2,
    "FASTER" : 1,
    "SLOWER" : 2
  },
  "entriesSize" : 3,
  "setEntries" : true,
  "setTime" : true
}

After receiving it I would like to retrieve the values of entries so that I know how many votes OK has, how many FASTER and how many SLOWER. If I try this by saying msg.data.entries.FASTER jQuery fails with TypeError: msg.data.entries is undefined. Why is that. I tried it in JS Fiddle and it just worked fine. See here. Does anybody know why jQuery is acting that strange and different in different environments? Thanks.

4

1 回答 1

0

First parse returned json string to object.

var jsonObject = $.parseJSON(msg);

Then access required data from decoded object.

e.g. var time = jsonObject.time;

于 2013-07-14T03:58:18.467 回答