[英]how to decode the encoded array passed from php
I have problem in decoding the array passed from PHP. 我在解码从PHP传递的数组时遇到问题。 My PHP code is
我的PHP代码是
$checkedJson = json_encode($dynamic_species);
$tmp = exec("/Python33/arr_pass.py $pressure $temp $checkedJson");
return $tmp;
If i print $checkedJson i get 如果我打印$ checkedJson我得到
{"species1":"CH4","species2":"C2H6"} as print statement
{“ species1”:“ CH4”,“ species2”:“ C2H6”}作为打印语句
My python code is 我的python代码是
species_list = sys.argv[3]
species_list_data = json.loads(species_list)
print(species_list_data['species1'])
This python script returns empty string as output to php 此python脚本返回空字符串作为输出到php
I am working for first time on JSON can anyone please help me. 我是第一次使用JSON工作,有人可以帮助我吗?
Thanks in advance 提前致谢
This is neither a JSON nor Python question. 这既不是JSON也不是Python问题。 What you want is to figure out how to get output back when your PHP program runs something via
exec()
. 您想要的是弄清楚当您的PHP程序通过
exec()
运行某些东西时如何获取输出。 Basically you're lacking the output parameter; 基本上,您缺少输出参数。 RTM at php.net .
php.net上的 RTM。 You should try:
你应该试试:
exec("/Python33/arr_pass.py $pressure $temp $checkedJson", $output);
After which $output
will be an array of lines that your exec'd script sent to its output. 之后,
$output
将是您的执行脚本发送到其输出的一系列行。 In your code, $tmp
is assigned to the last line that the exec'd thing prints, so probably an empty line. 在您的代码中,
$tmp
被分配给执行程序打印的最后一行,因此很可能是空行。
Plus you have one more challenge; 另外,您还有一个挑战; the way you pass
$checkdJson
to the Python script will fail. 将
$checkdJson
传递给Python脚本的方式将失败。 You will have to quote it to make it one commandline parameter, so you'll probably need 您必须将其引用以使其成为一个命令行参数,因此您可能需要
exec("/Python33/arr_pass.py $pressure $temp '$checkedJson'", $output);
(note the extra single quotes). (请注意多余的单引号)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.