JSONDecodeError Expecting property name enclosed in double quotes line 1 column 2 (char 1)
Python 在使用
json.loads()
方法时会报一个标题提到的错误,这是因为 JSON 格式的问题。
首先 JSON 格式数据本身规定字符串必须使用双引号来包裹,而
loads()
方法又没有做这方面的处理,想要解决 BUG 笨点办法就是用双引号替换单引号
当然更好的办法就是使用
ast
模块
1 2 3 4 5 6 7 8 9
|
import ast
text = "{'name': 'wxnacy'}" res = ast.literal_eval(text) print(res)
|
缺失模块。
1、请确保node版本大于6.2
2、在博客根目录(注意不是yilia根目录)执行以下命令:
npm i hexo-generator-json-content --save
3、在根目录_config.yml里添加配置:
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: false
tags: true