我已經成功地編寫了一個腳本來從json文件中提取信息,並以一種我可以使用的方式解析它,但我此刻必須手動打印每個字符串。我想循環這個如果可能但堅持從哪裏開始?python循環與JSON,而不是手動打印出每場比賽
的Python
from __future__ import print_function
import json
import sys
from pprint import pprint
with open('screen.json') as data_file:
data = json.load(data_file)
#json_file.close()
# Print all json data
#pprint(data)
#screen_list = data['screen']
print ("Screens availble",len (data['screen']))
#pprint(data["screen"][1]["id"])
#pprint(data["screen"][1]["user"])
#pprint(data["screen"][1]["password"])
#pprint(data["screen"][1]["code"])
#How to loop this
print ("https://",data["screen"][0]["server"],"/test/test.php?=",data["screen"][0]["code"],sep='')
print ("https://",data["screen"][1]["server"],"/test/test.php?=",data["screen"][1]["code"],sep='')
print ("https://",data["screen"][2]["server"],"/test/test.php?=",data["screen"][2]["code"],sep='')
JSON
{
"screen": [
{
"id": "1",
"user": "[email protected]",
"password": "letmein",
"code": "123456",
"server": "example.com"
},
{
"id": "2",
"user": "[email protected]",
"password": "letmein",
"code": "123455",
"server": "example.com"
},
{
"id": "3",
"user": "[email protected]",
"password": "letmein",
"code": "223456",
"server": "example.com"
}
]
}
這一個完美的作品 – Grimlockz
@Grimlockz,沒有後顧之憂,很高興它幫助。 –