使用json解析数据时,通常遇到这里就会出现问题'bytes' object has no attribute 'read',这是由于使用的json内置函数不同,一个是load另一个是loads。

import urllib.request
import json response = urllib.request.urlopen('http://www.reddit.com/r/all/top/.json').read()
jsonResponse = json.load(response) for child in jsonResponse['data']['children']:
print (child['data']['title'])

通常解决方式有两种,一种是更改函数为loads,另一种是更改编码格式为utf8

第一种解决方式:

jsonResponse = json.loads(response.decode('utf-8'))

第二种解决方式

使用json.loads()而不是json.load()

内容参考:https://stackoverflow.com/questions/6541767/python-urllib-error-attributeerror-bytes-object-has-no-attribute-read

最新文章

  1. 【C#公共帮助类】 Log4net 帮助类
  2. js日期重写
  3. 不错的判断 UITextView 内容不超过20个字符串的方法
  4. Unity破解for mac
  5. 93、App Links (应用程序链接)实例
  6. HDU 1506 Largest Rectangle in a Histogram
  7. hadoop的核心思想
  8. ibatis框架的sqlmapclient接口
  9. 关于dialog引起的 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView not attached to window manager 错误的分析
  10. kill -9杀掉nginx主进程、reload失败解决办法
  11. 计蒜客NOIP模拟赛(2)D1T3 深黑幻想
  12. 如何让minicom换行
  13. [leetcode](4.21)4. 有效子数组的数目
  14. springboot之mybatis注解形式
  15. java-log4j日志打印
  16. lfs(systemv版本)学习笔记-第4页
  17. myeclipse和maven的clean和build
  18. Cordova笔记(一)
  19. C# 读写opc ua服务器,浏览所有节点,读写节点,读历史数据,调用方法,订阅,批量订阅操作
  20. TCP-IP and Advanced Topics 课程总结与报告

热门文章

  1. 『转』Kaspersky Internet Security for Android &KMS – 免费6个月
  2. jQuery 参数详解
  3. ReactNative 问题集合
  4. vue music-抓取歌单列表数据(渲染轮播图)
  5. python安装openSSL
  6. Convex 一道阿姆斯特朗回旋好题
  7. 《DSP using MATLAB》Problem 2.10
  8. ambassador 学习七 Mapping说明
  9. Brackets编辑器使用
  10. FastAdmin 环境变量 env 配置