<?php
$obj = new stdClass();
$obj->return = '[
{
"date":"19.02.2021",
"time_start":"16:00:00",
"duration":900,
"time_end":"16:15:00",
"employee_id":"01234567890"
},
{
"date":"19.02.2021",
"time_start":"16:15:00",
"duration":900,
"time_end":"16:30:00",
"employee_id":"01234567890"
},
{
"date":"20.02.2021",
"time_start":"10:45:00",
"duration":900,
"time_end":"11:00:00",
"employee_id":"gbkdbfndsbvvfnsd"
}
]';
$json = json_decode($obj->return);
$res = array_map(function($item) {
return $item->date;
}, $json);
var_dump($res);
const Json = require('./my.json');
const fs = require("fs");
Json.push({
userId: 2,
id: 2
});
fs.writeFileSync("my.json", JSON.stringify(Json))
const json = `[{"id":124124,"firstname":"Районный","lastname":"Прокурор","warns":0,"role":11,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"botmute":0,"nick":"хай"},{"id":123123,"firstname":"Кто","lastname":"Никто","warns":0,"role":11,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"botmute":0,"nick":"пока"},{"id":125125,"firstname":"Крутой","lastname":"Поц","warns":0,"role":1,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"nick":"привет"}]`;
const data = JSON.parse(json);
function findNick(arr, nick) {
const res = arr.find(i => i.nick == nick);
if (res) return;
return arr;
}
console.log(findNick(data, 'хай'));
$.ajax({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/users',
dataType: 'json',
success: data => {
console.log(data)
//тут работаем с data. это преобразованный json которую мы получили в ответ от сервера
// проходим циклом и выводим в таблицу нужные данные
}
})
<script id="myJson" type="application/json">
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
</script>
let json = document.querySelector('#myJson');
let obj = JSON.parse(json.innerHTML);
console.log(obj);
fetch('https://jsonplaceholder.typicode.com/todos/1').then(res => res.json()).then(data => console.log(data))