次のようなデータを持つ 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 オブジェクト内の を参照します。今私が欲しいのは、指定された に対して、JSON オブジェクトからi
my を抽出evidence
し、それを表示することです (できれば、すべての文字列の後に改行を付けて)。