擅长:python、mysql、java
<p>这应该能做到这一点,而且比其他大多数解决方案都要短。在</p>
<pre><code>from collections import OrderedDict
data = []
for line in eventVar.readline():
# Remove braces
line = line.strip()[1:-1]
results = OrderedDict()
# Split by comma sign
for pair in line.split(','):
# Get key and value by splitting on colon
key, value = pair.split(':')
# Use eval to get rid of quotation surrounding the key and value
results[eval(key)] = eval(value)
# Add the results from reading this line to a list
data.append(results)
</code></pre>