擅长:python、mysql、java
<p>可以使用<code>ast.literal_eval</code>计算字符串并返回Python对象(如果语法正确)。<a href="https://stackoverflow.com/questions/15197673/using-pythons-eval-vs-ast-literal-eval">Using this is safer than using ^{<cd2>}</a>。你知道吗</p>
<pre><code>import ast
s = "[['Categories', [['180972'], ['180800'], ['16228'], ['32733'], ['32789'], ['32833'], ['325137'], ['32839'], ['25329'], ['42605'], ['428240849'], ['5101'], ['568'], ['570716'], ['57116'], ['57080545404'], ['57083134076']]], ['Tags', ['Stock', 'Color', 'Fam', 'Dress','Maxi']], ['Type', ['Luxary']], ['Vendor', ['AAA']]]"
l = ast.literal_eval(s)
d = dict(l)
{'Categories': [['180972'],
['180800'],
['16228'],
['32733'],
['32789'],
['32833'],
['325137'],
['32839'],
['25329'],
['42605'],
['428240849'],
['5101'],
['568'],
['570716'],
['57116'],
['57080545404'],
['57083134076']],
'Tags': ['Stock', 'Color', 'Fam', 'Dress', 'Maxi'],
'Type': ['Luxary'],
'Vendor': ['AAA']}
</code></pre>
<p>如果您还想摆脱内部列表,请使用<a href="https://stackoverflow.com/a/53932822/4042267">the other answer</a>,而不是只调用对象上的<code>dict</code>。你知道吗</p>