我有對象的Python列表,它看起來像這樣列表解析JSON在Python
[
<NodeImage: id=aki-00501552, name=ubuntu/kernels-testing/ubuntu-lucid-amd64-linux-image-2.6.32-341-ec2-v-2.6.32-341.42-kernel, driver=Amazon EC2 (ap-southeast-1) ...>,
<NodeImage: id=aki-00c4bd52, name=ubuntu-kernels/ubuntu-lucid-amd64-linux-image-2.6.32-316-ec2-v-2.6.32-316.31-kernel, driver=Amazon EC2 (ap-southeast-1) ...>,
<NodeImage: id=aki-015d1253, name=RH-pv-grub-hd00-V1.01-x86_64, driver=Amazon EC2 (ap-southeast-1) ...>, <NodeImage: id=aki-01f58a53, name=None, driver=Amazon EC2 (ap-southeast-1) ...>
]
我想它轉換爲JSON格式看起來像這樣,
[
{
"id":"aki-00501552", "name":"ubuntu/kernels-testing/ubuntu-lucid-amd64-linux-image-2.6.32-341-ec2-v-2.6.32-341.42-kernel","driver":"Amazon EC2 (ap-southeast-1)"
},
{
"id":"aki-00c4bd52", "name":"ubuntu-kernels/ubuntu-lucid-amd64-linux-image-2.6.32-316-ec2-v-2.6.32-316.31-kernel", "driver":"Amazon EC2 (ap-southeast-1)"
},
{
"id":"aki-015d1253", "name":"RH-pv-grub-hd00-V1.01-x86_64", "driver":"Amazon EC2 (ap-southeast-1)"
}
]
有一種做這種轉換的方法。
發佈的所有內容都是程序說明。但是,我們需要您[提出問題](http://stackoverflow.com/help/how-to-ask)。我們無法確定您想從我們這裏得到什麼。請[編輯]您的帖子以包含我們可以回答的有效問題。提醒:請確保你知道[這裏的主題是什麼](http://stackoverflow.com/help/on-topic),要求我們爲你編寫程序,而且建議不在話下。 –
是的,方法是編寫一些代碼。 –
寫一個自定義編碼器(串行器),並傳遞給它'json.dumps([...],默認= your_custom_encoder)' –