php - JSON数据转入php
问题描述
在我的 Linux 机器上,我使用了一个命令:
lightning-cli getinfo
这给了我 JSON 数据。
我尝试使用:
$jsonFile = "sh /bin/lightning-cli getinfo";
$jsondata = file_get_contents($jsonFile);
$data = json_decode($jsondata, true);
这给了我: PHP 警告:file_get_contents(sh /bin/lightning-cli getinfo): failed to open stream: No such file or directory ...
如何将数据导入 php?
解决方案
试试shell_exec
吧file_get_contents
$jsonFile = "sh /bin/lightning-cli getinfo";
$jsondata = shell_exec($jsonFile);
$data = json_decode($jsondata, true);
或者
直接呼叫
$jsonFile = "lightning-cli getinfo";
$jsondata = shell_exec($jsonFile);
$data = json_decode($jsondata, true);
推荐阅读
- python - 基于python中现有的数据框列创建多个新数据框
- javascript - 如何更改 pdf 页面上的图标?
- ios - 按 tabbar 并在 prefersLargeTitles = true iOS 中调用 Scroll to top
- deep-learning - 为什么 CNN 中使用的图像大小通常是特定数字?
- dart - 如何通过手势传递到下面的对象?
- javascript - Vuejs SSR、Laravel 和 PHP V8Js 问题“窗口未定义”
- python - 重命名目录中的文件时的 If-Else
- javascript - 为什么fillText没有出现在画布中?
- javascript - 即使在使用 window.location 重定向后,Chrome 也会继续加载资源
- regex - 如何为我的词法分析器使用正则表达式转义字符串文字?