假设我有带有这样数据的 JSON 对象(在单独的 .json 文件中):
evidenceStrings = [
{"jokeid": 0, "evidence": ["\My God you're right! I never would've thought of that!", "this look that says \My God you're right! I never would've thought of that!\", " \My God you're right! I never would've thought of that!\"]},
{"jokeid": 1, "evidence": ["the man didn't have to watch"]},
{"jokeid": 2, "evidence": ["knocking down trees with your face", "knocking down trees with your face. ", " knocking down trees with your face. ", "with your face.", "knocking down trees with your face"]}
]
我想在 HTML 文件中显示“证据”。问题是我正在从另一个 .js 文件中读取内容并使用 for 循环显示它的内容。
for(var i = 0; i < jokes.length; i++) {
// display string at index 0 of an array in a .js file
i
这里指的jokeid
是JSON对象中的。现在我想要的是,对于给定的i
,从 JSON 对象中提取 myevidence
并显示它(最好在每个字符串后面加上一个换行符。