python中将json字符串转换为dict

首先要确认是否存在simplejson的类库,python2.6及以上版本默认自带,

python2.5需要到如下目录下载

http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.2.tar.gz#md5=a856f9ae9ab3749991a93ddeafadc554

接下来的代码如下

import simplejson

js = "{/"description/":/"fdsafsa/",/"order/":/"1/",/"place/":/"22 Plainsman Rd, Mississauga, ON, Canada/",/"lat/":43.5969175,/"lng/":-79.7248744,/"locationDate/":/"03/24/2010/"},{/"description/":/"sadfdsa/",/"order/":/"2/",/"place/":/"50 Dawnridge Trail, Brampton, ON, Canada/",/"lat/":43.7304774,/"lng/":-79.8055435,/"locationDate/":/"03/26/2010/"},"

simplejson.loads('[%s]' % js[:-1])

 

三行代码搞定,为什么python代码总是那么简单呢

 

你可能感兴趣的:(json,python,import,2010)