擅长:python、mysql、java
<p>您可以尝试在删除所有不必要的头和尾字符后将所有数据转换为dict。在</p>
<pre><code>import re
line = 'unicode: {"Title":"The Fountain","Year":"2006","Rated":"R","Released":"22 Nov 2006","Genre":"Drama, Romance, Sci-Fi","Director":"Darren Aronofsky","Writer":"Darren Aronofsky, Darren Aronofsky","Actors":"Hugh Jackman, Rachel Weisz, Sean Patrick Thomas, Ellen Burstyn","Plot":"Spanning over one thousand years, and three parallel stories, The Fountain is a story of love, death, spirituality, and the fragility of our existence in this world.","Poster":"http://ia.media-imdb.com/images/M/MV5BMTU5OTczMTcxMV5BMl5BanBnXkFtZTcwNDg3MTEzMw@@._V1_SX320.jpg","Runtime":"1 hr 36 mins","Rating":"7.4","Votes":"100139","ID":"tt0414993","Response":"True"}'
def parser(text):
match = re.search(r'\{\"([^}]+)\"\}', text)
if match:
return dict(x.split('":"') for x in match.group(1).split('","'))
newdict = parser(line)
for k, v in newdict.items():
print k, v
</code></pre>
<p>我使用regex,但是它很容易被任何方法替换,在检索到的字符串中最多删除{“and after}”。在</p>