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代码总是那么简单呢
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)