Click here to Skip to main content
14,920,592 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need help trying to load a JsonData.json file into a javascript array.
My JsonData.json file structure is below:
[
    {
        "ID": 1,
        "Name": "John Smith",
        "IDNumber": "7606015012088"
    },
    {
        "ID": 2,
        "Name": "Molly Malone",
        "IDNumber": "8606125033087"
    },
    {
        "ID": 3,
        "Name": "Rianna Chetty",
        "IDNumber": "6207145122087"
    }
]

I am using the code below but I am getting an error: 'myList' is undefined
PHP
$.getJSON('JsonData.json')
   .done(function (data) {
       myList = data;
   });
Posted
Updated 25-Oct-13 4:09am
v3
Comments
Prasad Khandekar 25-Oct-13 10:12am
   
Where in your file this variable (myList) is declared?
Linkz_G 25-Oct-13 10:20am
   
the name of my array needs to be called myList
Prasad Khandekar 25-Oct-13 10:31am
   
Yes, but in your script you need to have the declaration. Try changing your code to something like one shown below.

var myList;
$.getJSON('JsonData.json')
.done(function (data) {
myList = data;
});

Regards,
   
Yes, this will solve the issue.
Member 13769644 24-Aug-18 5:51am
   
what is $.
it get me error $ not define

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month