Answer the question
In order to leave comments, you need to log in
How to insert json objects into a table?
C DB comes as a string String json :
{"tables": [{"Ext_TeleserviceCode":"11","Ellipsis":"","NACarrierID":"","CallingPartyNumber":"93967767","CamelBusy":"","GSM_ForwardingPending":"","EventTypeBCSM0":"C0"},
{"Ext_TeleserviceCode":"12","Ellipsis":"","NACarrierID":"","CallingPartyNumber":"93939643","CamelBusy":"","GSM_ForwardingPending":"","EventTypeBCSM0":"C0"}]}
function CreateTableFromJSON() {
var myBooks = [
{
"Book ID": "1",
"Book Name": "Computer Architecture",
"Category": "Computers",
"Price": "125.60"
},
{
"Book ID": "2",
"Book Name": "Asp.Net 4 Blue Book",
"Category": "Programming",
"Price": "56.00"
},
{
"Book ID": "3",
"Book Name": "Popular Science",
"Category": "Science",
"Price": "210.40"
}
]
Answer the question
In order to leave comments, you need to log in
It's all about parsing. Here you get a large JSON string as a JSON parameter. then do the following:
(json) => {
let parsedData = JSON.parse(json);
}
explain how you get json on the frontend? Php, Java on the back? Receive an object / array on the backend (a bunch of functions for everything), it is already output to the front from the array.
Assign the json string to the variable. We iterate in a loop and insert the data in the necessary places.
var collection = '{"tr": [{"td1": "name1","td2": "name2"},{"td1": "name1","td2": "name2"}]}';
var tr += '';
$.each(collection, function(i, tr){
tr += '<tr><td>'+tr.td1+'</td><td>'+tr.td2+'</td></tr>';
});
$('table').html(tr);
You can turn json into an object like this:
// json
var json = '{"foo": "bar", "lorem": "ipsum"}';
// Парсим в объект
var obj = JSON.parse(json);
// в цикле обходим свойства объекта
// добавляя значения в таблицу
for (var i in obj) {
var td = document.createElement('td');
td.innerHTML = obj[i];
tr.appendChild(td);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question