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 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单