我想让用户做出选择,并根据该选择我将钻入JSON数据并显示选定的信息。最终,我想创建一个下拉选择的HTML和JavaScript中的事件监听器,然后将检索。上述根据用户选择/提示检索JSON数据
var userOcean = prompt("Will you be fishing in the gulf or atlantic ?");
var userFish = prompt("What fish do you want to look up?");
console.log(
"\n\nfish: "+jsonObject.ocean_measure.userOcean.fish.userFish.name+
"\n\nlength: "+jsonObject.ocean_measure.userOcean.fish.userFish.length+
"\n\nclosed: "+jsonObject.ocean_measure.userOcean.fish.userFish.closed+
"\n\nlimit: "+jsonObject.ocean_measure.userOcean.fish.userFish.limit+
"\n\nremarks: "+jsonObject.ocean_measure.userOcean.fish.userFish.remarks
);
是Javascript和下面是JSON数据
var jsonObject = {
"ocean_measure" :
{
"gulf":
{
"fish": {
"dolphin": {
"name": "Mahi-mahi",
"length": "none",
"limit": "10 per person or 60 per vessel whichever is less"
},
"blackfin tuna": {
"name": "Blackfin Tuna",
"length": "not regulated",
"limit": "The default bag limit for all unregulated species is two fish or 100 pounds per day, whichever is more"
},
"snook": {
"name": "Snook",
"length": "Not less than 28 inches total length (TL) or more than 33 inches TL",
"closed": "Dec. 1-end of February; May 1-Aug. 31",
"limit": "1 per harvester per day",
"remarks": "Snook permit required for harvest when saltwater license required. State regulations apply in federal waters. Illegal to buy or sell snook. Fish must remain in whole condition until landed ashore (heads, fins, and tails intact). Snatch hooks and spearing prohibited. Harvest prohibited by or with the use of any multiple hook in conjuction with live or dead bait."
}
}
}
,
"atlantic":
{
"fish": {
"dolphin": {
"name": "Mahi-mahi",
"length": "20 inches fork length",
"limit": "10 per person or 60 per vessel whichever is less"
},
"blackfin tuna": {
"name": "Blackfin Tuna",
"length": "not Regulated",
"limit": "The default bag limit for all unregulated species is two fish or 100 pounds per day, whichever is more"
},
"snook": {
"name": "Snook",
"length": "Not less than 28 inches total length (TL) or more than 32 inches TL",
"closed": "Dec. 15 to Jan. 31, June 1 to Aug. 31",
"limit": "1 per harvester per day",
"remarks": "Snook permit required for harvest when saltwater license required. State regulations apply in federal waters. Illegal to buy or sell snook. Fish must remain in whole condition until landed ashore (heads, fins, and tails intact). Snatch hooks and spearing prohibited. Harvest prohibited by or with the use of any multiple hook in conjuction with live or dead bait."
}
}
}
}
}
我一直无法找到一种简单的方式,采取userInput和创建JSON文件,它的数据检索。
如果你想在这里工作的话,就是这个问题的链接。 http://stackoverflow.com/questions/38545522/html-select-value-passed-into-javascript-var-then-used-to-fetch-json – Carl