我有以下JSON结构,我需要迭代data.list的嵌套值。当我使用以下declare
type ab_rec is record (
a2 table2.a%type
, b2 table2.b%type
, a1 table1.a%type
, b1 table1.b%type
);
type ab_nt is table of ab_rec;
l_recs ab_nt;
begin
WITH
with_b AS
(
Select A, B from Table1
)
SELECT *
bulk collect into l_recs
FROM
(Select A, B from Table2) a, with_b b
WHERE a.A = b.A(+)
order by a.A;
.....
end;
进行硬编码时,我能够获得嵌套值,但是当我尝试迭代整个data.list对象时,我无法获得嵌套值。
console.log(data["list"][0]["My website is https://www.test.com"][0][0].command);
答案 0 :(得分:1)
您可以使用对象中的第一个键。
var data = { list: [{ "The first website is https://www.w3.org/": [[{ command: "This is dummy content", new: false, message: "This was fun to make" }]] }, { "The second website is https://www.mozilla.org": [[{ command: "This is the second command", new: true, message: "Lorem ipsum" }]] }], verified: false },
i;
for (i = 0; i < data.list.length; i++) {
console.log( data.list[i][Object.keys(data.list[i])[0]][0][0].command);
}
答案 1 :(得分:1)
因为列表中的项是对象,所以您在单独的循环中迭代它们。此外,您必须考虑到它是一个对象,因此您应该使用object属性作为索引而不是整数。
以下应该有效:
for (var i = 0; i < data.list.length; i++) {
// this doesn't work
for (var property in data.list[i]) {
console.log(data.list[i][property][0][0].command);
}
}