N
N
Nick Bukovskiy2017-04-24 17:38:03
PHP
Nick Bukovskiy, 2017-04-24 17:38:03

Can you explain how it is accessible what is json in php?

I read the definitions on the Internet and googled, but I can’t really understand why it is needed and what are the advantages of it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2017-04-24
@saboteur_kiev

If you need to transfer from one machine to another (or from one program to another) a string, you pass a string.
And if you need to transfer a data structure, for example, several ints, a couple of strings, an array with a nested array - here you can pack the entire data set in XML or JSON and transfer it, and on the other side it will unpack immediately into a ready-made structure.
JSON is more compact, XML is more powerful.
Both are supported in different programming languages ​​out of the box.
This is if in a nutshell.

A
Andrey Amsteady, 2017-04-24
@amsterdy

JSON is a special kind of string that can be parsed on any side. Through it, you can transfer data arrays. For example, from php to javascript.
PHP:

// передаем массив $arr на клиент в виде JSON
$arr = [
    'name' => 'Петр'
];

echo json_encode ($arr);

You will get a string like this.
JS:
// принимаем строку, парсим и получаем объект таким, каким он был на сервере в PHP
var r = JSON.parse ('{"name": "Петр"}');

alert (r.name);
// выведет "Петр"

console.log (r);

/*
Получится объект такого вида:

var r = {
    'name': 'Петр'
};
*/

R
Rishat Sultanov, 2017-04-24
@rishatss

When you implement a client-server application, you will immediately understand :) I was also skeptical about this :) And as soon as I saw all the beauty of JSON, I scolded myself for bad thoughts in his direction.)

S
Stanislav, 2017-04-24
@ExcluZZ

if extremely briefly: json is a data format
and it doesn’t matter in php, js or stupidly in a text file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question