首页 > 解决方案 > $.getJSON PHP 替代方案

问题描述

$.getJSON 可能会产生误导,但我想做的是通过 PHP 文件从 url 获取 JSON。

var url = "https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read";
$.getJSON(url, function (json) {
//DO SOMETHING WITH THE DATA
}

这在 javascript 中运行良好。当我从 url 谷歌获取 JSON 时,可能是因为我正在学习 PHP,但我似乎找不到有效的答案。或者当我用谷歌搜索 $.getJSON 时,我让人们试图从 PHP 文件中获取 Json。

我的所有数据都通过我通过调用 google 脚本访问的 googlesheet 存储,并将其发回,我可以获取我想要的信息,例如

json.records[0].NAME;

我想将一些数据传递给我无法理解的 PHP 文件。

任何帮助将不胜感激。

标签: phpgoogle-apps-script

解决方案


就像js一样简单:

$content = file_get_contents('https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read');
$data = json_decode($content); // return object
$data = json_decode($content, true); // return array

推荐阅读