我有一个像这样的JSON文件:
{
"E01": {
"AdvisorService": [
"raw/18_c.txt",
"raw/33_c.txt"
],
"Workfile": "raw/39_c.txt",
"DigitalImage": ["raw/41_c.txt"], // List of images in different XMLs
"Event": [ // List of events in different XMLs
"raw/44_c.txt",
"raw/59_c.txt",
"raw/60_c.txt",
"raw/63_c.txt",
"raw/64_c.txt",
"raw/65_c.txt",
"raw/66_c.txt",
"raw/67_c.txt",
"raw/68_c.txt",
"raw/69_c.txt"
],
"StatusChange": "raw/73_c.txt",
"EstimatePrintImage": "raw/40_c.txt",
"UnrelatedPriorDamage": "raw/42_c.txt",
"RelatedPriorDamageReport": "raw/43_c.txt"
},
"S01": "... similar structure as above"
}
如何创建如下对象:(假设XMLBase是所有这些对象的基类)
1) (AdvisorService类型的2个对象,因为列表中有2个项目)
type('AdvisorService', (XMLBase,), {'file_loc': 'raw/18_c.txt', 'estimate_type': 'E01'})
type('AdvisorService', (XMLBase,), {'file_loc': 'raw/33_c.txt', 'estimate_type': 'E01'})
2) (1个Workfile类型的对象,因为它有1个值)
type('Workfile', (XMLBase,), {'file_loc': 'raw/39_c.txt', 'estimate_type': 'E01'})
3) (1个DigitalImage类型的对象,因为它有1个值)
type('DigitalImage', (XMLBase,), {'file_loc': 'raw/41_c.txt', 'estimate_type': 'E01'})
4) (类型为Event的10个对象,因为它有10个值)
type('Event', (XMLBase,), {'file_loc': 'raw/44_c.txt', 'estimate_type': 'E01'})
... so on
5)所以