Here is my json:
{ "items": [{ "id" : 1, "name": "Bill Gates", "age": 43 }, { "id" : 2, "name": "Sergey Brin", "age": 33 }, { "id" : 3, "name": "Larry Page", "age": 34 },{ "id": 4, "name":"dsfsdfs", "age":34 }] } <script type="text/javascript"> $(function () { $.getJSON('/test2/obj/data/base.json', function (data) { // alert(data); for (var key in data['items']) { alert(" "+ key + " "+data[key]); } }); }); </script> How do i get an array in js? Parse does not roll, also need for to access elements. You need to drive this JSON into the table, and that's it!
Understood! stack.js - loads JSON - generates a table - gives it to index.php
$('document').ready(function(){ loadData(); }); function loadData() { //загружаю на страницу $.getJSON('objects.json', function (data) { // console.log(data); var out = ''; out+='<table class="table table-hover">'; out+='<thead>'; out+='<tr>'; out+='<th>Формат</th>'; out+='<th>Адрес</th>'; out+='<th>Завод</th>'; out+='<th>№ телефона заведующего</th>'; out+='<th>№ городского телефона </th>'; out+='<th> ФИО заведующего</th>'; out+='</tr>'; out+='</thead>'; out+='<tbody>'; for (var key in data){ out+='<tr>'; out+='<td>'+data[key]['format']+'</td>'; out+='<td>'+data[key]['adress']+'</td>'; out+='<td>'+data[key]['factory']+'</td>'; out+='<td>'+data[key]['phone1']+'</td>'; out+='<td>'+data[key]['phone2']+'</td>'; out+='<td>'+data[key]['fio']+'</td>'; out+='</tr>'; } out+='</tbody>'; out+='</table>'; $('#items').html(out); }) } JSON objects.json itself
{ "101" : { "format" : "АЗП-1", "adress" : "г. Скидель, ул. Ленина, 78Б", "factory" : "2302", "phone1" : "8-029-117-17-75", "phone2" : "", "fio" : "Стокиш Светлана Михайловна" }, "102" : { "format" : "АЗП-2", "adress" : "г. Скидель, ул. Ленина, 4", "factory" : "2303", "phone1" : "8-029-327-47-34", "phone2" : "", "fio" : "Сакович Тамара Анатольевна" }, "103" : { "format" : "АЗП-3", "adress" : "г. Скидель, ул. Кирова, 3а", "factory" : "2304", "phone1" : "8-044-585-88-48", "phone2" : "", "fio" : "Мулярчик Наталья Дмитриевна" } } And index.php
<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php"); $APPLICATION->SetTitle("Торговые объекты"); ?> <head> <link rel='stylesheet' href='css/bootstrap.css'> </head> <body> <div id="items"></div> <script src="js/jquery-3.2.1.min.js" async></script> <script src="js/stack.js" async></script> </body> <? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
JSON.parsethan not happy? - Rostyslav Kuzmovych