weixin_33739541 2016-01-06 20:14 采纳率: 0%
浏览 36

无法解析JSON数组

I have this json and trying to parse it using Ajax.

{
    "data1": ["1 06, 2016 23:27:11", "22.4", "26.3", "866.81"],
    "data2": [
        ["1 06, 2016 21:55:39", "1 06, 2016 22:05:49", "1 06, 2016 22:15:59", "1 06, 2016 22:26:10", "1 06, 2016 22:36:19", "1 06, 2016 22:46:30", "1 06, 2016 22:56:41", "1 06, 2016 23:06:51", "1 06, 2016 23:17:01", "1 06, 2016 23:27:11"],
        ["22.1", "22.2", "22.5", "22.6", "22.7", "21.5", "22.6", "22.6", "22.5", "22.4"],
        ["25.7", "26.8", "27.1", "27.2", "27.2", "26.3", "26.9", "26.7", "26.4", "26.3"],
        ["866.9", "866.64", "866.81", "866.61", "866.53", "866.65", "866.51", "866.65", "866.67", "866.81"]
    ],
    "data3": [
        ["1 03, 2016", "1 04, 2016", "1 05, 2016", "1 06, 2016"],
        ["21.8", "21.1", "20.5", "20.3"],
        ["23.8", "24.1", "24.2", "23.4"]
    ],
    "data4": [
        ["1 03, 2016", "1 04, 2016", "1 05, 2016", "1 06, 2016"],
        ["32.7", "28", "22.9", "23.5"],
        ["35.7", "32.8", "29.5", "28.5"]
    ],
    "data5": [
        ["1 03, 2016", "1 04, 2016", "1 05, 2016", "1 06, 2016"],
        ["869.31", "870.46", "867.2", "864.37"],
        ["872.57", "875.91", "875.54", "869.3"]
    ]
}

After parsing, the console shows this just as it is printed from php file. However, it can not find values when I'm trying to print a specified value in the console and gives me this error:

Uncaught TypeError: Cannot read property '0' of undefined

For example when printing first value of the array inside data1 object ("1 06, 2016 23:27:11") using:

var jsonData = $.ajax({
    url: "source.php",
    dataType:"json",
    async: false
    }).responseText;
console.log(jsonData);
console.log(jsonData.data1[0]);
  • 写回答

1条回答 默认 最新

  • 谁还没个明天 2016-01-06 20:30
    关注

    Try

    $.getJSON( "source.php", function( json ) {
      console.log(json.data1[0]);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度