【发布时间】:2012-04-03 22:00:44
【问题描述】:
我无法找到如何转换这样的元素的 python 列表:
[[["thisid", 24024502], ["points", [[["lat", 37.8732041], ["lon", -122.2562601]], [["lat", 37.8729153], ["lon", -122.2561566]]]], ["name", "Latimer Hall"]]
到这样的元素的json数组:
{"thisid": 24024502, "points": [{"lat": 37.8732041, "lon": -122.2562601}, {"lat": 37.8729153, "lon": -122.2561566}], "name": "Latimer Hall"}
基本上,我正在尝试将具有内部结构的列表列表转换为 json 中的相应列表。
Plain json.dumps(mylist) 只返回原始列表(我猜,这是因为它也是一个有效的 json 对象......)
非常感谢您提出的任何建议!
【问题讨论】:
-
为什么不使用字典来存储原始数据?这样会更容易使用,并且还可以序列化为您要查找的 JSON。