【发布时间】:2018-08-02 20:05:34
【问题描述】:
简而言之,对于数据科学课程,我在 Walmart 上运行一个循环 (Python 3) 来查询商品信息并构建一个以 JSON 格式保存的综合数据集。 (在这种情况下,笔记本电脑属于 walmart api 中的电子产品类别。)
问题: --我可以阅读第一组25个项目 --当我追加时,项目 26 +,创建类型错误
这是我的附加代码
a = []
if not os.path.isfile('filename.json'):
a.append(entry['items'])
with open('filename.json', mode='w') as f:
f.write(json.dumps(entry['items'], indent=4))
else:
with open('filename.json') as feedsjson:
feeds = json.load(feedsjson)
feeds.append(entry['items'])
with open('filename.json', mode='w') as f:
f.write(json.dumps(feeds, indent=4))
这是打印代码。仅适用于项目 1-25
filepath = os.path.join('filename.json')
with open(filepath) as jsonfile:
json_data = json.load(jsonfile)
for i in range(len(json_data)):
itemId = json_data[i]['itemId']
print(itemId)
【问题讨论】:
标签: python json python-3.x walmart-api