I am having a hard time parsing an array in python when the array is coming from a php file.
test.php
$count = 3;
$before_json = array("qwe","wer","ert");
print_r($before_json );
$after_json = json_encode($before_json );
echo $after_json;
$command = escapeshellcmd("test.py $after_json $count");
$output = shell_exec($command);
echo $output;
print_r($before_json ); will display - Array ( [0] => qwe [1] => wer [2] => ert )
echo $after_json; will display - ["qwe","wer","ert"]
py.test
import sys
after_json = sys.argv[1]
count = sys.argv[2]
print (device_id)
print (after_json) will print - [qwe,wer,ert]
print (after_json[1]) will print - q
How can I have it print out any of the 3 items that are in after_json?
jsonmodule, then you can usejson.loads(after_json)to turn the JSON string into a list. Update: I felt this should be an answer rather than a comment, but I'll leave the comment since it already has some upvotes.