javascript - 如何从php中的curl响应中获取特定值

标签 javascript php curl

我使用curl得到以下格式的响应:

{
    "result": {
        "total": 1,
        "userquery": "my own query",
        "items": [
            {
                "coord": {
                    "a": -326.9159528,
                    "b": 12.0192037
                }
            }
        ]
    }
}

我想保存“a”:和“b”:之后的部分,所以只有这两组数字会保存在php变量中。

我该怎么做?最好的方法是什么?

最佳答案

您收到的数据是 JSON。您需要使用 json_decode() 解码数据然后访问变量:

$data = json_decode($curl_response);

$a = $data->result->items[0]->coord->a;
$b = $data->result->items[0]->coord->b;

Example/Demo

关于javascript - 如何从php中的curl响应中获取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37312260/

相关文章:

regex - 正则表达式模式中组模式的重复

javascript : Transform not working

php - 当相关下拉列表刷新页面时,将输入框值存储为变量

php - 如何计算网格中选中复选框的记录

python - 为什么使用Python请求GET请求gz数据时出现ConnectionError

php - 在 PHP 中使用 CURL 将登录 POST 到远程 auth 函数/php 文件

javascript - Android 4.3 默认浏览器 : xmlDoc. 评估抛出 INVALID_EXPRESSION_ERR:DOM Xpath 异常 51

javascript - jQuery 文件上传总是失败并显示 "File upload aborted"

javascript - 将 Pretender 与 Ember CLI 结合使用

PHP filesize() 在文件 > 2 GB