Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery-Ajax-如何读取下面的嵌套JSON_Javascript_Jquery_Json - Fatal编程技术网

Javascript Jquery-Ajax-如何读取下面的嵌套JSON

Javascript Jquery-Ajax-如何读取下面的嵌套JSON,javascript,jquery,json,Javascript,Jquery,Json,我有下面的JSON,下面是。我正在尝试读取过滤器中的所有值,以便可以单独显示所有值。 实例 0.49476509719035和 住宿等分开 azIndexDescPages也一样 例2 azIndexDescPages guid-3B5470AA-4683-11DF-A523-8C6895261AFF 名称-有关影响树的信息 shortURL-有关影响树的信息 我有点不确定如何得到这些值 如何获取值过滤器、字母组和azIndexDescPages //JSON { "view": "se

我有下面的JSON,下面是。我正在尝试读取过滤器中的所有值,以便可以单独显示所有值。 实例 0.49476509719035和 住宿等分开

azIndexDescPages也一样

例2 azIndexDescPages

guid-3B5470AA-4683-11DF-A523-8C6895261AFF

名称-有关影响树的信息

shortURL-有关影响树的信息

我有点不确定如何得到这些值

如何获取值过滤器、字母组和azIndexDescPages

//JSON

{
    "view": "search-category",
    "keyword": "Services",
    "filters": [{
        "0.494765097719035": "Accommodations"
    }, {
        "0.7564062477523095": "Support Services"
    }, {
        "OATH": "Administrative"
    }],
    "num-results": 20,
    "data": [{
        "alphabeticalGroup": "Services and Bags",
        "azIndexDescPages": [{
            "guid": "8A5C58E6-BECE-11DC-8E9F-96DAE110FEB8",
            "name": "General Vendor ",
            "shortURL": "general-vendor",
            "parenthicalCategory1": null,
            "parenthicalCategory2": null,
            "keyword": null,
            "shortDesc": "General Vendor blah blah.",
            "isRenew": true,
            "isApply": true,
            "descAmbiguousPages": null
        }]
    }, {
        "alphabeticalGroup": "Bages",
        "azIndexDescPages": [{
            "guid": "3B5470AA-4683-11DF-A523-8C6895261AFF",
            "name": "Information About Impacting Lorem",
            "shortURL": "information-about-lorem",
            "parenthicalCategory1": null,
            "parenthicalCategory2": null,
            "keyword": null,
            "shortDesc": "Lorem IPSUM Lorem IPSUM, etc.",
            "isRenew": null,
            "isApply": null,
            "descAmbiguousPages": null
        }, {
            "guid": "F560F636-4682-11DF-91AF-EA6C84051BF5",
            "name": "lorem ipsum 3",
            "shortURL": "information-about-lorem-ipsum-3",
            "parenthicalCategory1": null,
            "parenthicalCategory2": null,
            "keyword": null,
            "shortDesc": "New new new lorem ipsum.",
            "isRenew": null,
            "isApply": null,
            "descAmbiguousPages": null
        }]
    }]
}
//JavaScript

 function ajaxProcess() {

        var searchTerm = $("#term").val(); // get the user-entered search term on Enter key
        var URL2 = '/json/search-category-view.json';
        var tags = "&tags=" + searchTerm;
        //var tagmode="&tagmode=any";
        var jsonFormat = "&format=json";
        var ajaxURL = URL2 + "?" + tags + jsonFormat;


        $.ajax({
            url: ajaxURL,
            dataType: "json",
            //jsonp:"jsoncallback",
            success: function(data, textStatus, jqXHR) {

                console.log("Data " + data);
                //var jsonData = $.parseJSON(data);
                console.log("data, textStatus, jqXHR " + data + textStatus + jqXHR)

                $.each(data, function(i, result) {
                    console.log(" i" + [i] + " --" + result);
                    console.log(" <br\>" + [i] + " --" + result.filters);
                    //if (result.filters) {
                        // html += '<div class="quote">';
                        $.each(data.filters, function(i, filter) {
                            console.log("<br>  filter " + [i] + " --" + filter['i']);
                            //html += '<div class="quote-line">' + line + '</div>';
                        });

                        $.each(data.data, function(k, data) {
                            console.log("<br> Data alphabeticalGrou " + [k] + " --" + data.alphabeticalGroup);
                            console.log("<br> Data azIndexDescPages" + [k] + " --" + data.azIndexDescPages);
                            //html += '<div class="quote-line">' + line + '</div>';
                        });


                   // }



                    var searchResult = "";
                    searchResult += "<br>" + result[i] + "ss " + i;
                    searchResult += "<br> keyword-- " + this['keyword'];

                    $("#gallery").append(searchResult).fadeIn(200);



                });

            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log('FAILED to get  JSON from AJAX call' + jqXHR + textStatus + errorThrown);

            }
        });


    }

下面是一个结合使用json循环、Object.keys、eval和一些条件以及嵌套循环的解决方案。。我不认为这是一个最佳的解决方案,但它确实满足了需要。。。。我认为可以更好地重构JSON对象,以获得更好的性能和结果

//JSON var jsonObject={ 视图:搜索类别, 关键词:服务业, 过滤器:[{ 0.49476509719035:住宿 }, { 0.7564062477523095:支持服务 }, { 宣誓:行政 }], 数值结果:20, 数据:[{ 字母组:服务和行李, azIndexDescPages:[{ guid:8A5C58E6-BECE-11DC-8E9F-96DAE110FEB8, 名称:一般供应商, shortURL:一般供应商, parenthicalCategory1:null, parenthicalCategory2:null, 关键词:空, shortDesc:一般供应商的废话。, 伊斯伦新:是的, 伊莎普利:没错, 释义:null }] }, { 字母组:Bages, azIndexDescPages:[{ guid:3B5470AA-4683-11DF-A523-8C6895261AFF, 名称:有关影响Lorem的信息, 关于lorem的信息, parenthicalCategory1:null, parenthicalCategory2:null, 关键词:空, 短描述:Lorem IPSUM Lorem IPSUM等。, isRenew:null, isApply:null, 释义:null }, { guid:F560F636-4682-11DF-91AF-EA6C84051BF5, 姓名:lorem ipsum 3, 短网址:information-about-lorem-ipsum-3, parenthicalCategory1:null, parenthicalCategory2:null, 关键词:空, shortDesc:新的lorem ipsum。, isRenew:null, isApply:null, 释义:null }] }] } //代码 jQuery.eachjsonObject、functionkey、value{ ifkey==过滤器 { jQuery.eachvalue,functionnestedKey,nestedValue { var objectKey=Object.keysnestedValue[0]; var objectVal=evalnestedValue['+objectKey+']; //console.logevalnestedValue['+objectKey+']; $filters.appendobjectKey+'----'+objectVal+; }; } ifkey==数据 { jQuery.eachvalue,functionnestedKey,nestedValue { jQuery.eachnestedValue.azIndexDescPages,functionnestedKey,nestedValue { jQuery.eachnestedValue,functionnestedKey,nestedValue { console.lognestedValue; $data.appendnestedKey+'----'+nestedValue+; }; }; $data.append; }; } }; 过滤器: 数据:
你的小提琴坏了。请让你的小提琴工作,并复制问题