python使用json.loads时出现raise JSONDecodeError(“Expecting value“, s, err.value) from None

import json
data_json = '{"name":"abc", "age":NumberInt(19)}'
data_dict = json.loads(data_str)

运行时候会报如下错误:

raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 22 (char 21)

分析可能是NumberInt数据类型不是Expecting value。尝试把NumberInt改成数字,发现问题迎刃而解。如何把json字符串中的“NumberInt(19)”转换为“19”呢?如果只有一个这种的还好办,很多NumberInt的话就不太容易了。这时可以用正则表达式来进行替换操作,详见文章末尾的链接。

import json
data_json = 

猜你喜欢

转载自blog.csdn.net/shiyuzuxiaqianli/article/details/107522498