Ich versuche, den Benutzer eine Auswahl treffen zu lassen und basierend auf dieser Auswahl bohre ich in die JSON-Daten und zeige ausgewählte Informationen an. Letztendlich möchte ich eine Dropdown-Auswahl in HTML und Event-Listener in Javascript erstellen, die dann abgerufen werden würde.Abrufen von JSON-Daten basierend auf Benutzerauswahl/Eingabeaufforderung
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
);
oben sind die Javascript und unten ist die JSON-Daten
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."
}
}
}
}
}
Ich habe es nicht gelungen, einen einfachen Weg zu finden userinput zu nehmen und einen Datenabruf mit aus JSON-Datei zu erstellen.
Ich habe einen „Part Two“, wenn Sie auf diese kleine Anwendung ich Ich arbeite mit, wenn Sie möchten, hier ist der Link zu dieser Frage. http://stackoverflow.com/questions/38545522/html-select-value-passed-into-javascript-var-then-used-to-fetch-json – Carl