问题
input = json.load(sys.stdin)
print(input['id'])
When I input {"id":1} and hit enter, my program does not continue, I am just stuck typing in my input. How can I make the program continue after valid json has been passed to my stdlin?
回答1:
when you read in from sys.stdin
it will read everything until it hits an EOF character normally ctrl-d so if you input {"id":1} <ENTER> ctrl-d
it should work.
It looks like what you are trying to do is something like this
import json
json_as_str = input()
json_obj = json.loads(json_as_str)
print(json_obj['id'])
来源:https://stackoverflow.com/questions/50180360/trouble-with-python-json-input-from-stdin