0
當前,試圖將以下list
項導入到11個不同的列(列表中的每個項目進入不同的列)。我認爲問題的根源在於我在python
腳本中使用的方法需要具有以下格式:[(1,2,3,...,11),(1,2,3,...,11)]
基本上是由導致tuples
的括號分隔的行列表。Python將JSON和商店列表解析爲SQLite表
我的代碼嘗試:
import sqlite3
import json
lst = []
with open('data.json') as data_file:
data = json.load(data_file)
for e in data:
if e == 'participants':
continue
#participants_data=data['participants'][0]
#print participants_data
#for f in participants_data:
# print f
# print participants_data[f]
else:
lst.append(data[e])
# print e
# print data[e]
conn = sqlite3.connect('somedbname.sqlite')
c = conn.cursor()
c.execute('''CREATE TABLE if not exists stocks33
(col1 text, col2 text, col3 text, col4 text, col5 text, col6 text, col7 text, col8 text, col9 text, col10 text, col11 text)''')
c.executemany("INSERT INTO stocks33 VALUES (?,?,?,?,?,?,?,?,?,?,?)", lst)
conn.commit()
c.execute("select * from stocks33")
print(c.fetchall())
數據:
{
"matchId": 1778839570,
"region": "NA",
"platformId": "NA1",
"matchMode": "CLASSIC",
"matchType": "MATCHED_GAME",
"matchCreation": 1427867835805,
"matchDuration": 3424,
"queueType": "RANKED_SOLO_5x5",
"mapId": 11,
"season": "SEASON2015",
"matchVersion": "5.6.0.194",
"participants": [
{
"teamId": 100,
"spell1Id": 4,
"spell2Id": 11,
"championId": 113,
"highestAchievedSeasonTier": "GOLD"
}
]
}
你在得到什麼,你期待什麼? –