+ 1

How to get a json array in localhost to web GUI. Please help

In the backend order is automatically generated, and a json array is obtained in the end point. It should be loaded to a table in gui.

19th Jul 2020, 7:47 AM
Sandali Harshani
Sandali Harshani - avatar
7 Antworten
+ 5
Sandali Harshani Your json response contains Array of objects. So you can access data like this for(var k = 0; k < arr.length; k++) { var obj = arr[k]; var id = obj.id; var name = obj.name; var supplier = obj.supplier; var weight = obj.weight; var location = obj.location; } See the output Here: https://code.sololearn.com/WnNhq0M1O47w/?ref=app
19th Jul 2020, 8:13 AM
A͢J
A͢J - avatar
+ 3
You can also use map array method. https://code.sololearn.com/W7szX2OLX4JH/?ref=app
19th Jul 2020, 11:45 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 2
In this array are objects with keys and values. Where is your concrete problem? Did you make your attempt, please link it from the Playground?
19th Jul 2020, 8:04 AM
JaScript
JaScript - avatar
+ 2
So accessing data as above. After that stay still generating of a table. Unfortunstelly we have no more details about how shall be look the table. I would like to start as follows: for (let element of data) { let row = table.insertRow(); for (key in element) { let cell = row.insertCell(); let text = document.createTextNode(element[key]); cell.appendChild(text); } }
19th Jul 2020, 12:27 PM
JaScript
JaScript - avatar
+ 1
Please show the json array sample or format
19th Jul 2020, 7:51 AM
Calviղ
Calviղ - avatar
+ 1
[{"id":"mars","name":"Mars","supplier":"Nestle","weight":1,"location":"a1.1/A"},{"id":"kitkat","name":"Kit Kat","supplier":"Nestle","weight":1,"location":"a1.1/A"},{"id":"dd","name":"Double Decker","supplier":"Nestle","weight":1,"location":"a1.1/A"},{"id":"mars","name":"Mars","supplier":"Nestle","weight":1,"location":"a1.1/A"},{"id":"kitkat","name":"Kit Kat","supplier":"Nestle","weight":1,"location":"a1.1/A"},{"id":"dd","name":"Double Decker","supplier":"Nestle","weight":1,"location":"a1.1/A"}]
19th Jul 2020, 7:55 AM
Sandali Harshani
Sandali Harshani - avatar
19th Jul 2020, 12:29 PM
Calviղ
Calviղ - avatar