weixin_33716941 2012-09-21 17:40 采纳率: 0%
浏览 49

从JSON对象获取数据

I'm working on my first (EVER!) JSON project, and I'm wondering how to get data from a JSON object. I've imported it in, and what I need to do is get the input from the value field and compare it to an input the user has entered. Unfortunately, I can't even figure out how to get data from the JSON object. It seems to be loading successfully, but I can't reference it. Here' s a sample of the JSON I'm loading:

{
    "films": [{
        "label": "34",
        "value": "34",
        "currently_streaming": "1",
        "full_streaming_url": "http://www.url.com",
        "url": "http://www.url.com"},
    {
        "label": "A Different Color",
        "value": "A Different Color",
        "currently_streaming": "1",
        "full_streaming_url": "http://www.url.php",
        "url": "http://www.url.com"}]
}​

And here's the code that loads it. It returns as successful, but I can't get any of the data from the JSON object:

 $(document).ready(function(){
    $.ajax({
        dataType: 'json',
        beforeSend : function() {
           console.log('Before Ajax Request Starts !!');
        },
        success: function(data) {
            console.log(data);
            alert("Edddddddd");
            $.each(json.films, function(i, object) {
            $.each(object, function(property, value) {
            alert(property + "=" + value);
    });
});
        },
        error : function(jqXHR, textStatus, errorThrown) {
             alert("Error occurred: " + errorThrown);
        },
         beforeSend : function() {
           console.log('Ajax Request Complete  !!');
        },
        url: 'test.php'
    });  
});

I clearly have no idea what I'm doing, and so would really appreciate any help!

  • 写回答

1条回答 默认 最新

  • weixin_33749131 2012-09-21 17:44
    关注

    Change from:

    $.each(json.films, function(i, object)
    

    to:

    $.each(data.films, function(i, object)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置