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
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.