In a recent discussion on Stack Overflow, I encountered an issue while trying to extract a specific name from a JSon file named winners.json. The structure of the file resembles this:
{"driver":[
{
"Year":1984,
"Name":"Name1",
},
{
"Year":1985,
"Name":"Name2",
},
[and so forth...]
]}
Within my JavaScript file, I am utilizing a slider feature to select a year that corresponds to the data in the JSon file. Despite confirming that the selected value is of type "number" through console logs, I am facing difficulties retrieving the corresponding "Name" field due to unexpected issues with the "Year" field:
var len=winners.winner.length;
console.info(len + " values in JSon");
for (var i=0; i < len; i++) {
console.info("Reading line " + i + " Type: " + typeof(winners.winner[i].Year) + " Year: " + winners.winner[i].Year);
[additional code...]
}
While the variable len is being read correctly, attempts to resolve the issue by casting Number(winners.winner[i].Year) have resulted in NaN errors.
Your insights and assistance are greatly appreciated.