如何获取整个json主体作为用户输入并存储在变量中

时间:2019-07-05 02:07:40

标签: python json python-3.x user-input

我想将下面的json正文作为用户输入存储在变量中并传递给变量,它在多行输入中


     {
     "key1": "value1",
     "key2": "value2",
     "key3": "value3",
     "key4": "value4",
     "key5": "value5",
     "key6": "value6",
     "key7": "value7",
     "key8": "value8"
     }

我在下面尝试过

import json
allow = json.dumps(input("Enter your Json body: "))
print(allow)
print(json.loads(allow))

variable = {
 "key1": "value1",
 "key2": "value2",
 "key3": "value3",
 "key4": "value4",
 "key5": "value5",
 "key6": "value6",
 "key7": "value7",
 "key8": "value8"
 }

我需要将多行变量作为同一JSON主体传递给函数。

0 个答案:

没有答案