如何读取json.txt和解析json python READ TXT PYTHON [英] how to read json.txt and parse json python READ TXT PYTHON
本文介绍了如何读取json.txt和解析json python READ TXT PYTHON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个txt文件:resultJSON.txt
I have one txt file: resultJSON.txt
txt文件中的数据为JSON格式.
the data in the txt file is in JSON format.
{
"term": "dog",
"results": [{
"filename": "1.jpg",
"numberID": "D12"
}, {
"filename": "23.jpg",
"number": "E52"
}]
}
我想将txt读入python并解析JSON.
I would like to read the txt into python and parse the JSON.
如何阅读txt ???
How to read the txt???
推荐答案
确保以下代码与resultJSON.txt
位于同一文件夹中:
Make sure the following code is in the same folder as resultJSON.txt
:
import json
with open('resultJSON.txt') as f:
json_data = json.load(f)
您的数据将保存在json_data
中.
这篇关于如何读取json.txt和解析json python READ TXT PYTHON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文