weixin_33744854 2015-07-31 14:35 采纳率: 0%
浏览 24

无法将Json转换为jQuery

This is my Ajax response from database :

{
    "docs": [{
        "_id":"5be81e62-f91d-4185-bef5-2eabdf048578",
        "_rev":"6-171639a97982fd7d04a81ed070b2e752",
        "profile_id":"5be81e62-f91d-4185-bef5-2eabdf048578",
        "name":"omar"
    }],
    "bookmark": "g2wAAAABaANkAB9kYmNvcmVAZGI1LmplbmV2ZXIuY2xvdWRhbnQubmV0bAAAAAJuBAAAAADAbgQA_____2poAkY_8AAAAAAAAGEBag"
}

I want to convert it to jQuery for Example :

var JsonData = jQuery.parseJSON(responseData.Value);
alert(JsonData.docs._id);

But the alert message show : undefined Need your help please and thanks.

  • 写回答

1条回答 默认 最新

  • weixin_33724059 2015-07-31 14:39
    关注

    docs is an array. An arrays store multiple docs in a single variable.

    You need to tell the runtime which doc you want to attain the _id property of.

    In your case there is only one doc so you can access the first using an index initializer:

    alert(JsonData.docs[0]._id);
    

    The [0] part pulls the first doc from the array.

    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)