访问JSON数据数组元素

时间:2014-10-13 06:40:54

标签: javascript json

我有以下JSON数据:

{
    "data": [
        {
            "count": 1194,
            "time_bin": "2014-10-06"
        },
        {
            "count": 1237,
            "time_bin": "2014-10-07"
        },
        {
            "count": 1144,
            "time_bin": "2014-10-08"
        },
        {
            "count": 1072,
            "time_bin": "2014-10-09"
        },
        {
            "count": 1082,
            "time_bin": "2014-10-10"
        },
        {
            "count": 406,
            "time_bin": "2014-10-11"
        },
        {
            "count": 465,
            "time_bin": "2014-10-12"
        }
    ],
    "error_flag": 0,
    "message": "7 rows returned"
}

我想访问" count"分别。我怎么能这样做?

1 个答案:

答案 0 :(得分:-1)

也许是这样的?

 var jsonData = { 
               data : [  {count:1194, time_bin:"2014-10-06"},
                            ...
                      ] , 
              error_flag:0, 
              message:"Here is your message"
         };
    var count;
    for (var i=0; i<jsonData.data.length; i++){
      count = jsonData.data[i].count;
      // do something
    }