我真的很难找到一种方法来以我喜欢的方式遍历这个对象。我在这里只使用 Javascript。
首先,这是对象
{
"dialog":
{
"dialog_trunk_1":{
"message": "This is just a JSON Test"
},
"dialog_trunk_2":{
"message": "and a test of the second message"
},
"dialog_trunk_3":
{
"message": "This is a test of a bit longer text. Hopefully this will at the very least create 3 lines and trigger us to go on to another box. So we can test multi-box functionality, too."
}
}
}
现在,我只是尝试基本方法来访问此对象上的每个 dialog_trunk。理想情况下,我想遍历对象并为每个树干显示它的message值。
我已经尝试使用 for 循环动态生成 dialog_trunk 的名称/编号,但是我无法使用对象名称的字符串访问该对象,因此我不确定从哪里开始。
