TypeError: the JSON object must be str, bytes or bytearray, not dict

目录

TypeError: the JSON object must be str, bytes or bytearray, not dict

问题:

解决:

完整错误:


问题:

import json
dic = {'a':123, 'b':"456", 'c':"liming"}
# dic_str = json.loads(str(dic).replace("'", "\""))
dic_str = json.loads(dic)
print(dic_str)

解决:

单引号的字符串不符合Json的标准格式所以再次使用了 replace("'", "\"")

import json
dic = {'a':123, 'b':"456", 'c':"liming"}
dic_str = json.loads(str(dic).replace("'", "\""))
# dic_str = json.loads(dic)
print(dic_str)

完整错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-402-239df5f3d40d> in <module>2 dic = {'a':123, 'b':"456", 'c':"liming"}3 # dic_str = json.loads(str(dic).replace("'", "\""))
----> 4 dic_str = json.loads(dic)5 print(dic_str)D:\anaconda\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)339     else:340         if not isinstance(s, (bytes, bytearray)):
--> 341             raise TypeError(f'the JSON object must be str, bytes or bytearray, '342                             f'not {s.__class__.__name__}')343         s = s.decode(detect_encoding(s), 'surrogatepass')TypeError: the JSON object must be str, bytes or bytearray, not dict

TypeError: the JSON object must be str, bytes or bytearray, not dict相关推荐

  1. TypeError: the JSON object must be str, bytes or bytearray, not NoneType

    来自后台flask 这里注意: 出现这种情况不一定是flask没有接收到数据, 而有可能是接收到数据,但是数据的解析代码有问题 最终代码如下: @app.route("/post_metho ...

  2. TypeError: expected str, bytes or os.PathLike object, not module

    TypeError: expected str, bytes or os.PathLike object, not module 目录 TypeError: expected str, bytes o ...

  3. pip安装库包遇到错误:TypeError: expected str, bytes or os.PathLike object, not int 的解决方法

    1 问题描述 1.在安装python3的库包时候,遇到和os模块相关的错误:TypeError: expected str, bytes or os.PathLike object, not int, ...

  4. 解决HuggingFace加载预训练模型时报错TypeError: expected str, bytes or os.PathLike object, not NoneType

    完整报错: TypeError: expected str, bytes or os.PathLike object, not NoneType 解决方法 检查下载的组件: 步骤1:完整的下载组件,包 ...

  5. TypeError: expected str, bytes or os.PathLike object, not int(解决方法)

    在使用 pip 安装软件时,报错如下 $ pip install numpy Exception: Traceback (most recent call last):   File "/u ...

  6. Python Socket TypeError: a bytes-like object is required, not 'str' 错误提示

    <python核心编程>第三版,发现示例2-1代码返回错误-..纠结很久  发现这里python3.5和Python2.7在套接字返回值解码上有区别.  先介绍一下 python byte ...

  7. 成功解决TypeError: a bytes-like object is required, not 'str'

    成功解决TypeError: a bytes-like object is required, not 'str' 目录 解决问题 解决思路 解决方法 解决问题 TypeError: a bytes- ...

  8. PyQt:成功解决Exception quot;unhandled TypeErrorquot; expected str, bytes or os.PathLike object, no

    PyQt:成功解决Exception "unhandled TypeError" expected str, bytes or os.PathLike object, no 目录 ...

  9. Python 3.5.2 TypeError: a bytes-like object is required, not 'str’问题解决方案

    运行环境Mac  Python 3.5.2 Q: http_response = """\ HTTP/1.1 200 OK Hello, World! "&qu ...

最新文章

  1. linux bash shell for 循环使用简介
  2. 数据结构与算法(C++版)
  3. document.getElementByName()的用法
  4. 将C4C Service Request中的summary和其他附件同步到ERP的Billing Request去
  5. 使用Outlook 2007连接到Exchange Server 2003、2007时出现没有默认网关的错误
  6. MySQL str_to_date()函数
  7. 在Azure Cloud Service中部署Java Web App(1)
  8. java中biglong_Java的long和bigint长度对比详解
  9. 别把SEO当苦力活,做优化要讲究策略
  10. 第三章 SQL知识点总结
  11. 微信小程序人脸识别获取照片,并解决相机拍照在ios上有声音问题
  12. 私域运营如何做到高转化高复购?快鲸scrm必不可少
  13. 如何快速入门Spring Cloud
  14. IE浏览器 请求报304,解决办法 设置页面禁止缓存
  15. 银屑病与大肠相关机制(调研手稿五)
  16. Python数据分析:柱形图的绘制方法
  17. vim编辑器删除键失效问题
  18. 1750套工装夹具检具治具机械设计机构solidworks模型3d课程图纸sw
  19. 通信电子电路(4)----高频功率放大器(2)
  20. 兽耳怎么画?怎样才能画好兽耳?

热门文章

  1. 绝对干货:19个有用的基于云的Web开发工具
  2. 互联网老师论坛高调炫耀收入:硕士毕业三年,月入九万多!
  3. Leangoo项目管理软件管理 传统硬件产品开发全流程
  4. 相机夜视原理——红外补光
  5. 长沙城南学院的计算机科学,长沙理工大学城南学院计算机科学与技术专业2016年在海南理科高考录取最低分数线...
  6. 中国科学院、东南大学等联合发表最新的视觉 Transformer 综述
  7. 点云滤波/分割/关键点提取/配准/识别/重建教程
  8. 超强激光SLAM LIO-SAM!高精度机器人定位建图!
  9. uNetXST:将多个车载摄像头转换为鸟瞰图语义分割图像
  10. form中的onblur事件简单的介绍