我试图在不使用成员名称的情况下从 Json 数组中获取下一个对象
i'm trying to get next object from Json Array without using member name
我试图在不提及成员名称的情况下获取 Json 数组中的下一个对象使用 Javascript
获取键值名称
var Commandjson = {
"commands": {
"MyObj.SubObj.Action.ActionEvent": {
"Id": "MyObj.SubObj.Action.ActionEvent.CustomAction",
"EnableRules": ["MyObj.SelectionCountExactlyOne"],
"Actions": [{
"ActionType": "3",
"Attributes": {
"FunctionName": "MyObj.Command.close"
},
"Parameters": [{
"Name": "",
"ParameterName": "",
"ParameterType": "21",
"Value": "Selected"
}]
}]
}
}
};
综上所述,
我正在尝试获取 Attributes
和 Parameters
我试过
Commandjson.commands[0].Actions[0].Attributes.FunctionName
但是出现错误
Uncaught TypeError: Cannot read property 'Actions' of undefined(…)
请帮我解决我遗漏的问题。
你最好使用
Commandjson.commands['MyObj.SubObj.Action.ActionEvent'].Actions[0].Attributes.FunctionName
因为commands不是一个数组,而是一个对象或者使用对象的键进行动态访问。
var Commandjson = {
"commands": {
"MyObj.SubObj.Action.ActionEvent": {
"Id": "MyObj.SubObj.Action.ActionEvent.CustomAction",
"EnableRules": ["MyObj.SelectionCountExactlyOne"],
"Actions": [{
"ActionType": "3",
"Attributes": {
"FunctionName": "MyObj.Command.close"
},
"Parameters": [{
"Name": "",
"ParameterName": "",
"ParameterType": "21",
"Value": "Selected"
}]
}]
}
}
};
var commands = Object.keys(Commandjson.commands); // get all commands
console.log(Commandjson.commands[commands[0]].Actions[0].Attributes.FunctionName);
我试图在不提及成员名称的情况下获取 Json 数组中的下一个对象使用 Javascript
获取键值名称var Commandjson = {
"commands": {
"MyObj.SubObj.Action.ActionEvent": {
"Id": "MyObj.SubObj.Action.ActionEvent.CustomAction",
"EnableRules": ["MyObj.SelectionCountExactlyOne"],
"Actions": [{
"ActionType": "3",
"Attributes": {
"FunctionName": "MyObj.Command.close"
},
"Parameters": [{
"Name": "",
"ParameterName": "",
"ParameterType": "21",
"Value": "Selected"
}]
}]
}
}
};
综上所述,
我正在尝试获取 Attributes
和 Parameters
我试过
Commandjson.commands[0].Actions[0].Attributes.FunctionName
但是出现错误
Uncaught TypeError: Cannot read property 'Actions' of undefined(…)
请帮我解决我遗漏的问题。
你最好使用
Commandjson.commands['MyObj.SubObj.Action.ActionEvent'].Actions[0].Attributes.FunctionName
因为commands不是一个数组,而是一个对象或者使用对象的键进行动态访问。
var Commandjson = {
"commands": {
"MyObj.SubObj.Action.ActionEvent": {
"Id": "MyObj.SubObj.Action.ActionEvent.CustomAction",
"EnableRules": ["MyObj.SelectionCountExactlyOne"],
"Actions": [{
"ActionType": "3",
"Attributes": {
"FunctionName": "MyObj.Command.close"
},
"Parameters": [{
"Name": "",
"ParameterName": "",
"ParameterType": "21",
"Value": "Selected"
}]
}]
}
}
};
var commands = Object.keys(Commandjson.commands); // get all commands
console.log(Commandjson.commands[commands[0]].Actions[0].Attributes.FunctionName);