python 之 json2
来源:互联网 发布:linux 父级目录 编辑:程序博客网 时间:2024/05/20 11:33
1.安装
下载 simplejson-2.6.1.tar
命令: tar -xf simplejson-2.6.1.tar 解压
然后:cd simplejson-2.6.1
安装命令:python setup.py install
安装完成
2.程序,注意编码问题
import simplejson
def read_jsonfile(file):
fd = open(file, 'r')
ls = fd.readline()
ls = ls.decode('gbk', 'ignore') # 注意
str = simplejson.loads(ls, encoding='gbk')
print str["feature"]["url"]
fd.close()
注意:
编码问题很关键,如果不制定gbk,会提示如下错误:
Traceback (most recent call last):
File "./json_lp.py", line 16, in <module>
read_jsonfile("gaohui.out")
File "./json_lp.py", line 11, in read_jsonfile
str = simplejson.loads(ls, encoding='gbk')
File "/home/work/local/python/lib/python2.5/site-packages/simplejson/__init__.py", line 468, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/home/work/local/python/lib/python2.5/site-packages/simplejson/decoder.py", line 406, in decode
obj, end = self.raw_decode(s)
File "/home/work/local/python/lib/python2.5/site-packages/simplejson/decoder.py", line 424, in raw_decode
obj, end = self.scan_once(s, idx=_w(s, idx).end())
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2: illegal multibyte sequence
- python 之 json2
- python 之 json2
- JSON2
- JSON2
- Json2
- json2
- json2
- json2使用方法
- JSON2 实例
- json2方法
- json2使用方法
- json2介绍
- WCF-json2
- json2使用方法
- Json2.js
- java中使用json2
- json2 转字符串问题
- php支持json2
- Eclipse主要用到的快捷键
- android与html5的交互——数据库操作,UI操作,以及html5的localStorage、定位功能
- 最牛B的 Linux Shell 命令 系列连载
- 调用宿主在Console的WCF报错
- VC中如何调用其他的可执行程序
- python 之 json2
- sql server 2005学习小记
- Linux查看内核、CPU等信息的常用命令
- SOA概述
- PHP CURL 模拟POST请求 提交数据或上传文件
- Linux学习笔记(一)
- How to determine whether crash dumps are USB or JTAG dumps on MDM9K?
- CentOS6.3下使用OpenSWAN做IPSecVPN的RoadWarrior模式 2
- 全面解析MFC应用程序中处理消息的顺序(转)