python
{'title': u'第一条新闻标题', 'description': u'第一条新闻描述,这条新闻没有预览图','picurl':u'http://img1.imgtn.bdimg.com/it/u=1779112580,3658566843&fm=15&gp=0.jpg', 'url':u'http://www.google.com.hk/',},{'title': u'第二条新闻标题, 这条新闻无描述', 'picurl':u'http://img1.imgtn.bdimg.com/it/u=599056397,2868563288&fm=21&gp=0.jpg','url':u'http://www.github.com/',},{'title': u'第三条新闻标题','description': u'第三条新闻描述','picurl':u'http://img1.imgtn.bdimg.com/it/u=599056397,2868563288&fm=21&gp=0.jpg','url': u'http://www.v2ex.com/',}
字符串如这样(这是字符串不是字典),我想把他转换成列表
python
[ { 'title': u'第一条新闻标题', 'description': u'第一条新闻描述,这条新闻没有预览图', 'picurl':u'http://img1.imgtn.bdimg.com/it/u=1779112580,3658566843&fm=15&gp=0.jpg', 'url':u'http://www.google.com.hk/', }, { 'title': u'第二条新闻标题, 这条新闻无描述', 'picurl':u'http://img1.imgtn.bdimg.com/it/u=599056397,2868563288&fm=21&gp=0.jpg', 'url':u'http://www.github.com/', }, { 'title': u'第三条新闻标题', 'description': u'第三条新闻描述', 'picurl': u'http://img1.imgtn.bdimg.com/it/u=599056397,2868563288&fm=21&gp=0.jpg', 'url': u'http://www.v2ex.com/', } ]
直接 list()是不行的,应该怎么办,用正则匹配出来吗
By observation, your string looks like a
Json
string. It is now popular to usejson
as a format for data transmission. I wonder if the two symbols[
and]
were missed in the source code of the post.Even if this is the case, you can also consider manually completing it into a
json
string, and then using thejson
libraryloads
to convert it into a list.eval('['+s+']')
If the string is eval directly, it may cause loopholes if the string is controllable by the user. It is recommended to use json parsing.