Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am a new developer ,

i have a problem about load json result in javascript

i have a javascript function to fetch data from API
and it was successfull

the result is like this

{
    "metadata": {
        "code": 200,
        "message": "OK"
    },
    "response": {
        "data": {
            "Data": [
                {
                    "Itemid": "11332",
                    "Userid": "3367",
                    "Username": "00202020",
                    "Firstname": "Ricki",
                    "Courseid": "10016",
                    "Shortname": "Kompetensi Inti",
                    "Itemname": "Introduction To Programming",
                    "Finalgrade": "8.00000"
                }
            ]
        }
    }
}


how can i load it into table or list view in javascript

What I have tried:

var ListValue = "";
                   //Variable created to iterate the json array values.
               var i;
               //Generic loop to iterate the response arrays.
               for (i = 0; i < response.length; ++i) {
                   ListValue += "<li>" + response[i].Itemid + " --- " + response[i].Courseid
               }

This is what i tried ,but response.length is undefined ,

how can i solve this?
Posted
Updated 1-Feb-23 19:07pm

1 solution

Look at the JSON data: response isn't an array, Data is.

Have a look here: Working with JSON - Learn web development | MDN[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900