Làm cách nào để lấy dữ liệu JSON từ API trong PHP?
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 Show 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 JSONTrong 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
|