weixin_33709590 2013-09-24 15:22 采纳率: 0%
浏览 14

从JSON树获取AJAX

I'm just starting out with AJAX, trying to use JQuery's $.getJSON function (or any related, ie $.load(), $.ajax(), etc). I have a JSON file with a structure something like this:

[
    {
        "id": 1,
        "email": "user@domain.com",
        "password": "password"
    },
    {
        "id": 2,
        "email": "one@two.com",
        "password": "password"
    }
]

How can I call a GET on this JSON file (let's call it users.json) for a user with a specific email? I thought it would be the second paramter in $.getJSON, but that seems to just return the whole tree.

Thanks!

  • 写回答

3条回答 默认 最新

  • weixin_33690367 2013-09-24 15:26
    关注

    Short answer - you can't do this directly with AJAX. jQuery can extract portions of HTML and XML documents, but not JSON.

    Easiest answer - retrieve the entire object (you have to, anyway) and use jsonpath to get the structure you want

    Longer answer - retrieve the entire object, and traverse it yourself to get the object you want

    Best answer - make the email address a parameter to whatever script produces the json and have the server only return the data you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器