如何访问一个JSON对象的数组? [英] How to access an array in a JSON object?

查看:382
本文介绍了如何访问一个JSON对象的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有以下的JSON对象:

Hello I have the following JSON object:

[
 {
  "comments":[
    {
     "created_at":"2011-02-09T14:42:42-08:00",
     "thumb":"xxxxxxx",
     "level":1,"id":214,
     "user_id":41,
     "parent_id":213,
     "content":"<p>xxxxxx</p>",
     "full_name":"xx K"
    },
    {
     "created_at":"2011-02-09T14:41:23-08:00",
     "thumb":"xxxxxxxxxxxxx",
     "level":0,
     "id":213,
     "user_id":19,
     "parent_id":null,
     "content":"<p>this is another test</p>",
     "full_name":"asd asd asd asd asd"
    }
  ],
 "eee1":"asdadsdas",
 "eee2":"bbbbb"
 }
]

这是从 $。阿贾克斯请求到来,成功,我有......

This is coming from a $.ajax request, in success I have....

    success: function (dataJS) {
        console.log(dataJS);
        console.log(dataJS[eee1]);
        console.log(dataJS.comments);
    }

问题是,我将无法访问在JSON对象中的项目,即使dataJS并在控制台中正确显示。想法?

Problem is I can't get access to the items in the JSON object, even though dataJS does show correctly in the console. Ideas?

感谢

推荐答案

那是因为你的基本对象是一个数组为好。

Thats because your base object is an array as well.

console.log(dataJS[0].comments[0]);

我怀疑,将工作

这篇关于如何访问一个JSON对象的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆