我想将json格式转换为表格。我希望json格式为“ dic列表”,但格式为“ unicode”。 如果它在“字典列表”中,那么我可以轻松地将其转换为表格
import json
import requests
url = "http://localhost:8080/api/vi/empdata"
headers = {
'cache-control': "no-cache",
'postman-token': "72c97887-727e-ae9e-36ed-182f725f"
}
response = requests.request("GET", url, headers=headers)
data = response.text
print(data)
for x in data:
print(x)
打印(数据)给出以下输出:
[{"name": "Aarush", "address": "Yoyager"}, {"name": "Sanju", "address":
"Victor"}, {"name": "Yara", "address": "Victor"}, {"name": "Zara",
"address": "Voyager"}]
print(x)给出以下输出:
[
{
"
n
a
m
e
"
:
"
A
a
r
u
s
h
"
,
"
a
d
d
r
e
s
s
"
:
"
Y
o
y
a
g
e
r
"
}
,
{
......goes on
我希望print(x)的输出为:
{'name': 'Aarush', 'address': 'Yoyager'}
{'name': 'Sanju', 'address': 'Victor'}
{'name': 'Yara', 'address': 'Victor'}
{'name': 'Zara', 'address': 'Voyager'}
答案 0 :(得分:0)
根据请求的版本,您可以使用:
data = response.json()
或
import json
...
data = json.loads(response.text)