JSON [Ký hiệu đối tượng JavaScript] là một định dạng trao đổi dữ liệu nhẹ. Nó dễ dàng được đọc và viết bởi con người và được máy móc phân tích cú pháp và tạo ra.
$ curl localhost:8000 John Doe is a gardener8 là loại phương tiện Internet chính thức cho JSON. Phần mở rộng tên tệp JSON là
$ curl localhost:8000 John Doe is a gardener9
Hàm
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]0 trả về biểu diễn JSON của giá trị đã cho.
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]1 lấy một chuỗi được mã hóa JSON và chuyển đổi nó thành một biến PHP
Các framework PHP như Symfony và Laravel có các phương thức tích hợp hoạt động với JSON
Mã hóa PHP JSON
Trong ví dụ sau, chúng ta sử dụng hàm
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]0
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.phpChúng tôi khởi động máy chủ và định vị tới
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]3Nhân vật. Chế độ xem JSON trong FirefoxCác trình duyệt web hiện đại hiển thị dạng xem JSON cho dữ liệu JSON khi chúng nhận được loại nội dung phù hợp trong tiêu đề của phản hồi
Trong ví dụ sau, chúng ta sử dụng hàm
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]1________số 8_______Chúng tôi bắt đầu máy chủ
$ curl localhost:8000 John Doe is a gardenerChúng tôi gửi một yêu cầu NHẬN với curl
PHP JSON được đọc từ tệp
Trong ví dụ sau, chúng tôi đọc dữ liệu JSON từ một tệp
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]Đây là dữ liệu JSON
Name Occupation Country name; ?> occupation; ?> country; ?>Trong ví dụ về mã, chúng tôi đọc tệp bằng
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]5 và giải mã nó thành một mảng PHP bằng[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]1. Sau đó, chúng tôi đặt dữ liệu vào một bảng bằng cách sử dụng vòng lặp PHP foreachTrong ví dụ sau, chúng tôi đọc dữ liệu từ cơ sở dữ liệu SQLite và trả về dưới dạng JSON
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;Mã SQL này tạo bảng
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]7 trong SQLite$ sqlite3 test.db sqlite> .read cities.sql sqlite> SELECT * FROM cities; 1|Bratislava|432000 2|Budapest|1759000 3|Prague|1280000 4|Warsaw|1748000 5|Los Angeles|3971000 6|New York|8550000 7|Edinburgh|464000 8|Berlin|3671000Với công cụ dòng lệnh
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]8, chúng tôi tạo cơ sở dữ liệu SQLite và tạo bảng[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]7query['SELECT * FROM cities']; $cities = []; while [$row = $res->fetchArray[]] { $cities[] = $row; } header['Content-type:application/json;charset=utf-8']; echo json_encode[['cities' => $cities]];Trong ví dụ, chúng tôi lấy dữ liệu từ cơ sở dữ liệu và trả về dưới dạng JSON
API tìm nạp PHP JSON và JS
Trong ví dụ sau, chúng tôi sử dụng API tìm nạp JavaScript để lấy dữ liệu JSON từ tập lệnh PHP
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]Dữ liệu JSON được lưu trữ trong một tệp
Quảng cáo The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php0Chúng tôi có một nút trong tài liệu. Khi chúng ta nhấp vào nút, hàm
Name Occupation Country name; ?> occupation; ?> country; ?>0 sẽ lấy dữ liệu JSON từ tập lệnhName Occupation Country name; ?> occupation; ?> country; ?>1. Một bảng HTML được tạo động và chứa đầy dữ liệuNhân vật. Bảng HTML chứa đầy dữ liệu JSON từ API tìm nạpTrong ví dụ sau, chúng tôi trả về dữ liệu JSON từ ứng dụng Slim
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php1Chúng tôi cài đặt các gói
Name Occupation Country name; ?> occupation; ?> country; ?>2,Name Occupation Country name; ?> occupation; ?> country; ?>3 vàName Occupation Country name; ?> occupation; ?> country; ?>4The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php2Chúng tôi sử dụng phương pháp
Name Occupation Country name; ?> occupation; ?> country; ?>5 củaName Occupation Country name; ?> occupation; ?> country; ?>6 để trả về dữ liệu JSONPHP JSON trong Symfony
Trong ví dụ sau, chúng tôi gửi phản hồi JSON từ ứng dụng Symfony
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php3Một ứng dụng mới được tạo
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php4Chúng tôi cài đặt các thành phần
Name Occupation Country name; ?> occupation; ?> country; ?>7,Name Occupation Country name; ?> occupation; ?> country; ?>8 vàName Occupation Country name; ?> occupation; ?> country; ?>9The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php5Chúng tôi thiết lập URL cơ sở dữ liệu cho cơ sở dữ liệu SQLite
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php6Chúng tôi tạo cơ sở dữ liệu
quảng cáosrc/Command/CreateCityTable. php
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php7Đây là lệnh tạo bảng
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]7 trong cơ sở dữ liệuQuảng cáo The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php8Lệnh được thực hiện
src/Kho lưu trữ/Kho lưu trữ thành phố. php
The example transforms a PHP array into a JSON string.
$ php -S localhost:8000 encode.php9Trong
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;1, chúng ta có phương thứcBEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;2 truy xuất tất cả các hàng. Chúng tôi sử dụng Doctrine DBAL để thực hiện truy vấn cơ sở dữ liệuquảng cáosrc/Bộ điều khiển/Bộ điều khiển thành phố. php
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php0Bên trong bộ điều khiển, chúng tôi tìm nạp tất cả dữ liệu bằng cách sử dụng
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;1. Dữ liệu được chuyển đổi thành JSON với trình trợ giúpBEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;4The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php1Chúng tôi khởi động máy chủ web và định vị tới
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;5PHP JSON trong Laravel
Trong ví dụ sau, chúng tôi gửi phản hồi JSON từ ứng dụng Laravel
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php2Chúng tôi tạo một ứng dụng Laravel mới
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php3Chúng tôi xác định kết nối và tệp cơ sở dữ liệu
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php4Chúng tôi tạo tập tin cơ sở dữ liệu
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php5Một lần di chuyển mới cho bảng
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]7 đã được tạoquảng cáo database/migrations/2020_07_25_101535_create_cities_table. php
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php6Trong tệp di chuyển, chúng tôi tạo một lược đồ cho bảng
[ {"name": "John Doe", "occupation": "gardener", "country": "USA"}, {"name": "Richard Roe", "occupation": "driver", "country": "UK"}, {"name": "Sibel Schumacher", "occupation": "architect", "country": "Germany"}, {"name": "Manuella Navarro", "occupation": "teacher", "country": "Spain"}, {"name": "Thomas Dawn", "occupation": "teacher", "country": "New Zealand"}, {"name": "Morris Holmes", "occupation": "programmer", "country": "Ireland"} ]7Quảng cáoThe example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php7Chúng tôi chạy di chuyển
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php8Chúng tôi tạo một trình gieo dữ liệu cho cơ sở dữ liệu của chúng tôi
cơ sở dữ liệu/hạt giống/CitySeeder. php
The example transforms a JSON string into a PHP variable.
$ php -S localhost:8000 decode.php9Seeder chèn tám hàng vào bảng
Quảng cáo$ curl localhost:8000 John Doe is a gardener0Chúng tôi thực hiện seeder
$ curl localhost:8000 John Doe is a gardener1Bên trong tuyến đường, chúng tôi chọn tất cả dữ liệu từ cơ sở dữ liệu và trả về dưới dạng JSON với trình trợ giúp
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;4$ curl localhost:8000 John Doe is a gardener2Chúng tôi chạy máy chủ web
$ curl localhost:8000 John Doe is a gardener3Chúng tôi lấy dữ liệu bằng công cụ
BEGIN TRANSACTION; DROP TABLE IF EXISTS cities; CREATE TABLE cities[id INTEGER PRIMARY KEY, name TEXT, population INTEGER]; INSERT INTO cities[name, population] VALUES['Bratislava', 432000]; INSERT INTO cities[name, population] VALUES['Budapest', 1759000]; INSERT INTO cities[name, population] VALUES['Prague', 1280000]; INSERT INTO cities[name, population] VALUES['Warsaw', 1748000]; INSERT INTO cities[name, population] VALUES['Los Angeles', 3971000]; INSERT INTO cities[name, population] VALUES['New York', 8550000]; INSERT INTO cities[name, population] VALUES['Edinburgh', 464000]; INSERT INTO cities[name, population] VALUES['Berlin', 3671000]; COMMIT;9Symfony cung cấp thành phần
$ sqlite3 test.db sqlite> .read cities.sql sqlite> SELECT * FROM cities; 1|Bratislava|432000 2|Budapest|1759000 3|Prague|1280000 4|Warsaw|1748000 5|Los Angeles|3971000 6|New York|8550000 7|Edinburgh|464000 8|Berlin|36710000 cho phép chúng tôi tạo các yêu cầu HTTP trong PHP. Chúng tôi cũng có thể gửi dữ liệu JSON$ curl localhost:8000 John Doe is a gardener4Chúng tôi cài đặt thành phần
$ sqlite3 test.db sqlite> .read cities.sql sqlite> SELECT * FROM cities; 1|Bratislava|432000 2|Budapest|1759000 3|Prague|1280000 4|Warsaw|1748000 5|Los Angeles|3971000 6|New York|8550000 7|Edinburgh|464000 8|Berlin|36710001$ curl localhost:8000 John Doe is a gardener5Ví dụ gửi yêu cầu GET với tải trọng JSON
quảng cáosrc/Trình điều khiển/Chào điều khiển. php
$ curl localhost:8000 John Doe is a gardener6Trong
$ sqlite3 test.db sqlite> .read cities.sql sqlite> SELECT * FROM cities; 1|Bratislava|432000 2|Budapest|1759000 3|Prague|1280000 4|Warsaw|1748000 5|Los Angeles|3971000 6|New York|8550000 7|Edinburgh|464000 8|Berlin|36710002, chúng tôi xử lý dữ liệu JSON và tạo một tin nhắn văn bản, tin nhắn này sẽ được trả lại cho khách hàngLàm cách nào để tìm nạp API JSON trong PHP?
Sử dụng dữ liệu từ JSON với PHP. Đầu tiên, để đi sâu vào việc JSON đó chỉ đơn giản là một chuỗi, chúng ta sẽ viết JSON thành một chuỗi PHP và áp dụng nó vào một biến có tên là $data . $data = '{ "tên". "Aragorn", "chủng tộc". "Nhân loại" }'; .Làm cách nào để lấy dữ liệu JSON từ URL API trong PHP?
Bạn có thể sử dụng hàm file_get_contents[] và hàm json_decode[] của PHP. .Tệp get_get_conents[] get được sử dụng để lấy hoặc đọc tệp từ đường dẫn đã cho [Url hoặc Nguồn]Hàm json_decode[] của PHP, dùng để convert nội dung file JSON sang PHP ArrayLàm cách nào để tìm nạp dữ liệu từ API trong PHP?
php // Bao gồm các lớp Yêu cầu và Phản hồi $url = 'https. //api. exoclick. com/v2/đăng nhập';Làm cách nào để gọi API JSON trong PHP?
Tệp PHP được giải thích. .Chuyển đổi yêu cầu thành một đối tượng, sử dụng hàm PHP json_decode[]Truy cập cơ sở dữ liệu và điền vào một mảng với dữ liệu được yêu cầuThêm mảng vào một đối tượng và trả về đối tượng dưới dạng JSON bằng hàm json_encode[]