這個數據看起來很簡單,你可以使用解析它無論是json.loads
或ast.literal_eval
(無論是在標準庫):
>>> a = """[
... [["L1603",1,5],[271585,972739],[272739,872739, 272739,972739, 271585,972739, 271585,272389, 270999,272389]],
... [["L1605",1,5],[271897,872739],[272739,872739, 272739,972739, 271891,872739, 271891,272119, 270963,272119]],
... [["L1607",1,4],[271584,272738],[271584,272738, 271584,272388, 270998,272388, 270998,272386]]
... ]
...
... """
>>> import ast
>>> ast.literal_eval(a)
[[['L1603', 1, 5], [271585, 972739], [272739, 872739, 272739, 972739, 271585, 972739, 271585, 272389, 270999, 272389]], [['L1605', 1, 5], [271897, 872739], [272739, 872739, 272739, 972739, 271891, 872739, 271891, 272119, 270963, 272119]], [['L1607', 1, 4], [271584, 272738], [271584, 272738, 271584, 272388, 270998, 272388, 270998, 272386]]]
>>> import json
>>> json.loads(a)
[[[u'L1603', 1, 5], [271585, 972739], [272739, 872739, 272739, 972739, 271585, 972739, 271585, 272389, 270999, 272389]], [[u'L1605', 1, 5], [271897, 872739], [272739, 872739, 272739, 972739, 271891, 872739, 271891, 272119, 270963, 272119]], [[u'L1607', 1, 4], [271584, 272738], [271584, 272738, 271584, 272388, 270998, 272388, 270998, 272386]]]
你可以很容易地從獲得(在我的例子a
)字符串
這就是我一直在尋找的一些神奇的直接1到1.謝謝! – scorpiknox