简体   繁体   中英

Getting "AttributeError: 'str' object has no attribute 'decode'"

I am a beginner. I can't get a json file to load as a string/dict in Python 3.

import json
data = open("Toys_and_Games_5.json", "r")
file = data.read().decode('utf-8')
reviews = json.loads(file)

Error:

AttributeError: 'str' object has no attribute 'decode'

This is all you need to do:

import json
data = json.load(open("Toys_and_Games_5.json"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM