首页 > 解决方案 > 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?

标签: phpjson

解决方案


试试shell_execfile_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);

推荐阅读