0

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.

Hawksteam
  • 13
  • 3
  • There seems to be an error with your JSON. Try changing "colors":["red"]["Green"], to "colors":["red","Green"] and "Identity":["L"]["p"]["t"] to "Identity":["L","p","t"] – cyber_rookie Oct 09 '16 at 11:10
  • I apologise i copied the json a little wrong you were right about how the colors and identity should be but it still says undefined in the console log – Hawksteam Oct 09 '16 at 16:09

0 Answers0