doushi1974 2014-12-11 12:04
浏览 52
已采纳

如何解码从PHP传递的编码数组

I have problem in decoding the array passed from PHP. My PHP code is

$checkedJson = json_encode($dynamic_species);
$tmp = exec("/Python33/arr_pass.py $pressure $temp $checkedJson");
return $tmp;

If i print $checkedJson i get

{"species1":"CH4","species2":"C2H6"} as print statement

My python code is

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

I am working for first time on JSON can anyone please help me.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • doujiayuan8415 2014-12-11 12:13
    关注

    This is neither a JSON nor Python question. What you want is to figure out how to get output back when your PHP program runs something via exec(). Basically you're lacking the output parameter; RTM at php.net. 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. In your code, $tmp is assigned to the last line that the exec'd thing prints, so probably an empty line.

    Plus you have one more challenge; the way you pass $checkdJson to the Python script will fail. 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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办