I am making an app which contains an external MYjsonfile.json
That file is set up like this
{
"Item1":{
"layout":"normal",
"name":"Item1",
"PIN":"{3}{5}{7}",
"code":5,
"colors":["Blue"],
"type":"index",
"Identity":["U"]},
"Item2":{
"layout":"normal",
"name":"Item2",
"PIN":"{4}{8}",
"code":9,
"colors":["Blue","Black"],
"type":"index",
"Identity":["L","U"]}}
I have this in my script
$.ajax({#
url: 'AllCards.json',
dataType: 'json',
type: 'get',
success: function (data) {
console.log(data);
}});
However, this gets all of the objects what i want to do is something like:
$.ajax({
url: 'AllCards.json',
dataType: 'json',
type: 'get',
success: function (data) {
var input = document.getElementById("userInput").value;
console.log(data.input);
}});
if you type in the input item1 the console logs it as undefined and does not get the object
Any help would be appreciated
FIXED ISSUE
The solution to this was to change console.log(data.input); to console.log(data[input]); the input has to be case sensitive to the item key but you can manipulate the string to complete that.