<legend id='GqyjS'><style id='GqyjS'><dir id='GqyjS'><q id='GqyjS'></q></dir></style></legend>

<small id='GqyjS'></small><noframes id='GqyjS'>

      <bdo id='GqyjS'></bdo><ul id='GqyjS'></ul>

      <i id='GqyjS'><tr id='GqyjS'><dt id='GqyjS'><q id='GqyjS'><span id='GqyjS'><b id='GqyjS'><form id='GqyjS'><ins id='GqyjS'></ins><ul id='GqyjS'></ul><sub id='GqyjS'></sub></form><legend id='GqyjS'></legend><bdo id='GqyjS'><pre id='GqyjS'><center id='GqyjS'></center></pre></bdo></b><th id='GqyjS'></th></span></q></dt></tr></i><div id='GqyjS'><tfoot id='GqyjS'></tfoot><dl id='GqyjS'><fieldset id='GqyjS'></fieldset></dl></div>
    1. <tfoot id='GqyjS'></tfoot>
    2. 访问嵌套属性 json

      时间:2023-10-15

      <small id='O0XK5'></small><noframes id='O0XK5'>

      <i id='O0XK5'><tr id='O0XK5'><dt id='O0XK5'><q id='O0XK5'><span id='O0XK5'><b id='O0XK5'><form id='O0XK5'><ins id='O0XK5'></ins><ul id='O0XK5'></ul><sub id='O0XK5'></sub></form><legend id='O0XK5'></legend><bdo id='O0XK5'><pre id='O0XK5'><center id='O0XK5'></center></pre></bdo></b><th id='O0XK5'></th></span></q></dt></tr></i><div id='O0XK5'><tfoot id='O0XK5'></tfoot><dl id='O0XK5'><fieldset id='O0XK5'></fieldset></dl></div>

          <legend id='O0XK5'><style id='O0XK5'><dir id='O0XK5'><q id='O0XK5'></q></dir></style></legend>
            <tbody id='O0XK5'></tbody>

                <bdo id='O0XK5'></bdo><ul id='O0XK5'></ul>
              • <tfoot id='O0XK5'></tfoot>
              • 本文介绍了访问嵌套属性 json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有这个 json:

                {"objects":[{"text":{"x":643,"y":71,"width":82,"height":33,"font":"Arial","style":"bold","size":24,"label":"Part A"}},
                {"text":{"x":643,"y":116,"width":389,"height":42,"font":"Arial","style":"bold","size":16,"label":"What does "novel" mean as it is used in paragraph 8 of "Turning Down a New Road"? "}},
                {"radiobutton":{"x":643,"y":170,"width":100,"height":20,"label":"A. old"}},{"radiobutton":{"x":643,"y":209,"width":100,"height":20,"label":"B. afraid"}},
                {"radiobutton":{"x":643,"y":250,"width":100,"height":20,"label":"C. new"}},
                {"radiobutton":{"x":643,"y":289,"width":100,"height":20,"label":"D. friendly"}}]}
                

                我需要获取每个元素的属性,但是我无法获取二级属性,我的意思是我不知道元素是文本"、单选按钮"、标签",我三级属性没问题.

                I need to get the properties of each element, but I can't get the property of second level, I mean I cant know if the element is a "text","radiobutton","label", I have no problem with the propeties of third level.

                这是我的来源:

                                   $.ajax({
                                        url: 'generateobject.php',
                                        dataType: 'json',
                                        type: 'GET'
                                    }).done(function(data) {
                                        $.each(data, function(index, firstLevel) {
                                            $.each(firstLevel, function(anotherindex, secondLevel) {
                                                alert(secondLevel[0]);//shows [object Object]
                                                $.each(secondLevel, function(yetAnotherIndex, thirdLevel) {
                                                    //alert(thirdLevel.y+''+thirdLevel.y);
                                                });
                                            });
                                        });
                                    });
                

                如何获得二级属性?

                推荐答案

                使用 Object.keys(data) 并访问第一项.如果您运行该代码段,您应该会看到预期的类型警报:

                Use Object.keys(data) and access the first item. If you run the snippet you should see the types alert as expected:

                var data = {"objects":[{"text":{"x":643,"y":71,"width":82,"height":33,"font":"Arial","style":"bold","size":24,"label":"Part A"}},
                {"text":{"x":643,"y":116,"width":389,"height":42,"font":"Arial","style":"bold","size":16,"label":"What does "novel" mean as it is used in paragraph 8 of "Turning Down a New Road"? "}},
                {"radiobutton":{"x":643,"y":170,"width":100,"height":20,"label":"A. old"}},{"radiobutton":{"x":643,"y":209,"width":100,"height":20,"label":"B. afraid"}},
                {"radiobutton":{"x":643,"y":250,"width":100,"height":20,"label":"C. new"}},
                {"radiobutton":{"x":643,"y":289,"width":100,"height":20,"label":"D. friendly"}}]};
                
                
                $.each(data, function(index, firstLevel) {
                  $.each(firstLevel, function(anotherindex, secondLevel) {
                    alert(Object.keys(secondLevel)[0]);
                    $.each(secondLevel, function(yetAnotherIndex, thirdLevel) {
                      //alert(thirdLevel.y+''+thirdLevel.y);
                    });
                  });
                });

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

                这篇关于访问嵌套属性 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何从 PHP 数组为下拉选择字段创建嵌套列表? 下一篇:mongodb 在查找查询中获取 _id 作为字符串

                相关文章

                <legend id='xGpPT'><style id='xGpPT'><dir id='xGpPT'><q id='xGpPT'></q></dir></style></legend>

                <small id='xGpPT'></small><noframes id='xGpPT'>

                  <bdo id='xGpPT'></bdo><ul id='xGpPT'></ul>

              • <tfoot id='xGpPT'></tfoot>
                  <i id='xGpPT'><tr id='xGpPT'><dt id='xGpPT'><q id='xGpPT'><span id='xGpPT'><b id='xGpPT'><form id='xGpPT'><ins id='xGpPT'></ins><ul id='xGpPT'></ul><sub id='xGpPT'></sub></form><legend id='xGpPT'></legend><bdo id='xGpPT'><pre id='xGpPT'><center id='xGpPT'></center></pre></bdo></b><th id='xGpPT'></th></span></q></dt></tr></i><div id='xGpPT'><tfoot id='xGpPT'></tfoot><dl id='xGpPT'><fieldset id='xGpPT'></fieldset></dl></div>