主要是要写个BOM
import json
import csv
f = open('d:\\brand.json')
data = json.load(f)
f.close()
file = open("d:\\brand.csv", "wb+")
file.write('\xEF\xBB\xBF');
f = csv.writer(file)
# Write CSV Header, If you dont need that, remove this line
f.writerow([u"ID", u"英文名", u"中文名", u"品牌名", u"状态"])
for x in data:
# print x.__class__
print [x["VALUE_ID"][0],
x["NAME_EN"][0] if x.has_key("NAME_EN") else "",
x["NAME_CN"][0] if x.has_key("NAME_CN") else "",
x["NAME"][0],
x["STATUS"][0] if x.has_key("STATUS") else ""
]
f.writerow([x["VALUE_ID"][0],
x["NAME_EN"][0] if x.has_key("NAME_EN") else "",
x["NAME_CN"][0] if x.has_key("NAME_CN") else "",
x["NAME"][0],
x["STATUS"][0] if x.has_key("STATUS") else ""
])