Python读取json文件,并转化为字典进行提取字段(出现索引must be int,not str)解决方案
2017-07-04 17:51
886 查看
Python读取json文件,并转化为字典进行提取字段(出现索引must be int,not str)解决方案
def craw_file(): di_review_keyword=[] for i in range(10): with open('E:\python_py\景区详情\\test\\'+'北京'+'_'+str(0)+'_'+str(1)+'.json','r') as file: #d读取文件,并转换成json格式 html=file.read() # html_json=json.loads(html) #以json形式加载 # # print(type(html),type(html_json)) html_dict=eval(html) #将其转化为字典并进行提取(一般出现索引must be int,not str) print(type(html_dict),html_dict) html_result=html_dict["result"] #基本信息 name=html_result["name"] address=html_result["address"]
相关文章推荐
- 手把手教你 python读取文件报错:ValueError encoding must be one of 'utf_8', 'big5', or 'gbk'.
- Python+Selenium进行UI自动化测试项目中,常用的小技巧1:读取excel表,转化成字典(dict)输出
- 解决python2.X从json文件中读取数据进行unicode转码情况
- python mysql 插入的数据是字典时,可以直接插入到数据库,不要进行for循环读取每一个字段
- Python txt文件读取写入字典的方法(json、eval)
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- C#读取Json文件出现乱码解决方案
- python解析json时出现“string indices must be integers”
- React 使用fromidable 模块进行文件上传出现First argument must be a string 的解析错误的原因
- python通过对字典的排序,对json字段进行排序
- mySQL给空间字段建立索引出现错误All parts of a SPATIAL index must be NOT NULL的解决办法
- 读取页面返回字典值提示错误:TypeError: string indices must be integers, not str
- python读取文件中的序列,将字符串形式序列转化并求值(eval)
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- IIS7虚拟目录出现HTTP错误500.19(由于权限不足而无法读取配置文件)的解决方案
- IIS7虚拟目录出现HTTP错误500.19(由于权限不足而无法读取配置文件)的解决方案
- Java读取UTF-8格式txt文件第一行出现乱码——问号“?”的解决方案
- ArcGIS+Python读取flt文件并进行区域统计
- windows java读取utf-8编码文件时出现第一个字符为未知字符"?" 的解决方案
- 使用CStdioFile 读取Unicode文件时出现乱码问题解决方案