简体   繁体   English

使用Jquery解析具有索引或位置而不是键名的JSON对象?

[英]Parse the JSON Object with Index or position instead of keyname using Jquery?

My Existing Code and Explanation 我现有的代码和解释

Working Fine, But I want to Create a template like Its should read JSON Data that Having keys in any name , I am Always reading data from JSON object in 2nd Position 工作正常,但是我想创建一个模板,例如它应该读取具有任何名称的键的JSON数据 ,我始终从第二位置的JSON对象读取数据

Now I read the JSON that passed in the argument (data) inside that using the for loop extract single object in group, after that get the data using key(Module_Name).. I know the key(Module_Name) is always present in second position only, Now its Working Fine with keyname rather i want to fetch the data using position, that also used as template in my other modules 现在,我读取了使用for循环提取组中单个对象的参数(数据)中传递的JSON,然后使用key(Module_Name)获取数据。我知道key(Module_Name)始终位于第二位置只是,现在它可以很好地使用键名,而我想使用位置来获取数据,该位置也用作我其他模块中的模板

/* render Screen Objects */
screenRenderer.displayScreens = function(data) 
{
     screenRenderer.renderLayout(function(cont, boo)
    {
        if (boo) 
        {

            for(i=0;i<data.length;i++)
            {

            var buttons = "<button class='screen_button'>"+data[i].Module_Name+"</button>";
                $("#screen-cont").append(buttons);

            }
        }
        else 
        {
            scr_cont.show();
        }
    })
}

This is My Requirement, kindly awaiting suggestions, answers.. Thanks in Advance 这是我的要求,请等待建议,答案.. 在此先感谢

You can use the function Object.keys(obj) to get all keys of an object as array, which you can access with an Index and than use the String you get to access the property. 您可以使用函数Object.keys(obj)来获取对象的所有键作为数组,您可以使用索引来访问它们,然后使用获得的String来访问属性。

So it could look like this: 所以看起来可能像这样:

var obj = data[i];
var keys = Object.keys(obj);
var result = obj[keys[1]];

Hope this is what you want. 希望这就是你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM