python str转dict_在python中将str转换为dict
实际上,旧版本的rddtool导出ECMA脚本,而不是JSON.根据
this debian bug report升级1.4.8应该给你合适的JSON.另见项目
CHANGELOG:
JSON output of xport is now actually json compilant by its keys
being properly quoted now.
如果你无法升级,你有两个选择;要么尝试重新格式化以应用引用对象键标识符,要么使用更宽松的解析器并解析ECMA脚本对象表示法.
>>> import demjson
>>> demjson.decode('''\
... { about: 'RRDtool xport JSON output',
... meta: {
... start: 1401778440,
... step: 60,
... end: 1401778440,
... legend: [
... 'rta_MIN',
... 'rta_MAX',
... 'rta_AVERAGE'
... ]
... },
... data: [
... [ null, null, null ],
... [ null, null, null ],
... [ null, null, null ],
... [ null, null, null ],
... [ null, null, null ],
... [ null, null, null ]
... ]
... }''')
{u'about': u'RRDtool xport JSON output', u'meta': {u'start': 1401778440, u'step': 60, u'end': 1401778440, u'legend': [u'rta_MIN', u'rta_MAX', u'rta_AVERAGE']}, u'data': [[None, None, None], [None, None, None], [None, None, None], [None, None, None], [None, None, None], [None, None, None]]}
修复可以使用正则表达式完成;我将假设所有标识符都在新行上或直接在打开{花括号之后.列表中的单引号必须更改为双引号;只有在值中没有嵌入的单引号时,这才有效:
import re
import json
yourtext = re.sub(r'(?:^|(?<={))\s*(\w+)(?=:)', r' "\1"', yourtext, flags=re.M)
yourtext = re.sub(r"'", r'"', yourtext)
data = json.loads(yourtext)
python str转dict_在python中将str转换为dict相关推荐
- [转载] python中将str转成数字_python如何将字符转换为数字
参考链接: 在Python中将字符串转换为数字并将数字转换为字符串 python中的字符数字之间的转换函数int(x [,base ]) 将x转换为一个整数 long(x [,base ...
- python整数转换字符串_使用Python中的str()函数将整数值转换为字符串
python整数转换字符串 Given an integer value and we have to convert the value to the string using str() func ...
- 【转】python 字符编码与解码——unicode、str和中文:UnicodeDecodeError: 'ascii' codec can't decode...
原文网址:http://blog.csdn.net/trochiluses/article/details/16825269 摘要:在进行python脚本的编写时,如果我们用python来处理网页数据 ...
- python中str和input_对python中raw_input()和input()的用法详解
最近用到raw_input()和input()来实现即时输入,就顺便找了些资料来看,加上自己所用到的一些内容,整理如下: 1.raw_input() raw_input([prompt]) -> ...
- python中str转unicode_python将unicode和str互相转化的实现
问题一: 将u'\u810f\u4e71'转换为'\u810f\u4e71' 方法: s_unicode = u'\u810f\u4e71' s_str = s_unicode.encode('uni ...
- 【Python】【Python库】Python3.7.2 - 字符串str类 (2)
文章目录 str类的其他方法 (Cont.) str.encode(encoding="utf-8", errors="strict") str.startsw ...
- 【Python】【Python库】Python3.7.2 - 字符串str类 (1)
文章目录 str类简介 str的构造函数/方法 str的其他方法 str.capitalize() str.casefold() 与str.lower() str.center(width [, fi ...
- python中str表示什么意思_python的str是什么类型
Python(特指Python 3)中包含字符串,字符串的类型为str,字符串是Unicode码点(Unicode code codepoint)的序列,属于不可变类型. 字符串有三种写法: 单引号( ...
- 计算机语言中str是什么意思,python中str函数的作用是什么
python中str函数的作用是什么 发布时间:2021-04-27 16:12:24 来源:亿速云 阅读:56 作者:Leah python中str函数的作用是什么?相信很多没有经验的人对此束手无策 ...
最新文章
- jquery学习(3)--高级选择器
- ILSpy可以反编译c语言,ILSpy反编译工具的使用
- OA学习笔记-001-项目介绍
- java整形怎么转字符串型_java整型与字符串互转
- linux下执行scrapy的爬虫定时任务
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
- Spring Cloud 5分钟搭建教程(附上一个分布式日志系统项目作为参考)
- 《计算机网络》第一章:基础知识Part I
- java.net.BindException: Address already in use解决方法
- node中使用shell脚本
- 如何成为一名游戏设计师
- 渐进记号的相关证明(使用极限的方式)
- ibm服务器查看刀片状态,IBM刀片服务器 blade center s常见问答
- dvwa通关教程超详细
- DRAM知识整理系列(三):部分时序参数整理
- 形容等待时间长的句子_形容等待了很久的句子
- linux设置python环境变量
- Python正则re模块详解
- 输入一个整数,判断它是几位数
- 2021 第四届 浙江省大学生网络与信息安全竞赛技能赛 决赛 Writeup,5题
热门文章
- 基于FFmpeg-4.0 SDK的PCM编码成AAC
- Ice笔记--C++线程与并发(小结)
- Ice笔记-利用Ice::Application类简化Ice应用
- 吴恩达深度学习课程deeplearning.ai课程作业:Class 4 Week 4 Art Generation with Neural Style Transfer
- mac安装telnet 超简单 复制telnet文件即可
- shell在二级python_在Shell脚本中检查Python版本的方法
- 手工纸盒子_不锈钢水槽如何选购,拉伸水槽与手工槽制造工艺有何区别
- weka: exhaustive search
- intel 965集成显卡开启ubuntu9.10的3d效果
- [蓝桥] 算法提高 队列操作