1
這是一個有效的JSON對象嗎?使用Python的有效JSON
{"Age": "2", "Name": "Rice, Master. Eugene", "Parch": "1", "Pclass": "3", "Ticket": "382652", "PassengerId": "17", "SibSp": "4", "Embarked": "Q", "Fare": "29.125", "Survived": "0", "Cabin": "", "Sex": "male"}
我需要EOF嗎?
我已經使用以下內容來創建該文件:
import json
import sys
fieldnames=["PassengerId","Survived","Pclass","Name","Sex","Age","SibSp","Parch","Ticket","Fare","Cabin","Embarked"]
csvfile=open('t1.csv','r')
jsonfile = open('file1.json', 'w')
reader = csv.DictReader(csvfile, fieldnames)
for row in reader:
# if reader.line_num ==1:
#continue # Skip the first line
json.dump(row, jsonfile)
jsonfile.write('\n')
print("Total No of Lines Wriiten : "+ str(reader.line_num))
是的,那就是JSON。您可以通過在瀏覽器中打開開發工具(在Chrome中按Ctrl + Shift + j)並在控制檯中鍵入'JSON.parse('...')'來測試它。 –