1、这是主要代码
import json
import csv
with open('12_.json',encoding='utf-8') as f:
json_file = json.load(f)
#选取json表中features中的内容
arr = json_file['data']
print(arr)
#声明6列的二维空列表用于存储数据
csv_list =[[]*5]*len(arr)
#声明空列表临时存储每行的数据
s = []
j = 0
for i in range(len(arr)):
#添加需要的字段
s.append(arr[i]['parkingName'])
s.append(arr[i]['totalSpace'])
s.append(arr[i]['feeDesc'])
s.append(arr[i]['sysProvider'])
s.append(arr[i]['address'])
print(s)
2、运行完之后报错KeyError: 0提取不到,没有值
E:\Software\Python\Python39\python.exe F:/text1/爬虫/pc2.py
Traceback (most recent call last):
File "F:\text1\爬虫\pc2.py", line 17, in <module>
s.append(arr[i]['parkingName'])
KeyError: 0
3、这是json文件里面的内容
{
"status":200,
"message":"成功",
"data":{
"id":"343",
"parkingName":"海口秀英万达广场停车场",
"totalSpace":1025,
"availSpace":null,
"feeDesc":"0-0.5h/ 免费,0.5-3h/5元,(3+N)h/(5+N)元,24h≥25元\n",
"sysProvider":"ETCP",
"longitude":"110.286517",
"latitude":"19.986165",
"address":"海南省海口市秀英区海榆中线29号万达广场",
"minFreeTime":0,
"city":"海口市",
"parkingStatus":"1",
"openStatus":"1",
"fastPay":"1",
"fpTypes":[
"WXV",
"ETC"
],
"seekEnabled":0,
"minFreeTimeDesc":null,
"feeTimeDesc":null,
"discountDesc":null,
"topFee":2900,
"minFeeDesc":"{\"time\":30,\"rule\":\"分钟\"}",
"feeRule":"1小时内收费5元,2小时内加收2元",
"openAt":"",
"closeAt":"",
"wxBizcleEnabled":false,
"invoiceMode":1,
"supChannel":1,
"remark":"1、停车免费时长30分钟 ;\n2、30分钟(含)后到1小时收费5元;\n3、1-2小时(含)收费2元,不足1小时按1小时计算;\n4、2小时后每小时收费1元,不足1小时按1小时计算,24小时29元封顶;\n5、停车超出24小时后,重新累计收费,无免费时长,即1小时内收费5元,1-2小时(含)收费2元,2小时后每小时收费1元,不足1小时按1小时计算,每24小时封顶29元,以此累计叠加。\n6、临时车提前缴费后,需在20分钟内离场,否则产生二次计费,二次计费无免费时长,每小时收费1元,不足1小时按1小时收费。",
"activities":[
],
"searchCarMode":{
"open":false,
"provider":null,
"appId":null,
"linkUrl":null
},
"appointmentMode":{
"open":false,
"provider":null,
"appId":null,
"linkUrl":null
},
"passcodeSupported":true
}
}
问题报错怎么解决