我正在处理要使用lb4进行建模的深层嵌套对象。我有机会获得有关此示例JSON代码的帮助吗?
{
"cardAcceptor": {
"address": {
"city": "Foster City",
"country": "RU",
"county": "San Mateo",
"state": "CA",
"zipCode": "94404"
},
"idCode": "ABCD1234ABCD123",
"name": "ABCD",
"terminalId": "ABCD1234"
},
"destinationCurrencyCode": "840",
"markUpRate": "1",
"retrievalReferenceNumber": "201010101031",
"sourceAmount": "100",
"sourceCurrencyCode": "643",
"systemsTraceAuditNumber": "350421"
}
您可以为嵌套对象创建单独的模型,
例如上述数据结构
您可以有类似的东西
export class CardAcceptor extends Address {
@property({
type: 'string',
required: true,
})
address: string;
@property({
type: 'string',
required: true,
})
idCode: string
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'string',
required: true,
})
terminalId: string;
constructor(data?: Partial<CardAcceptor>) {
super(data);
}
}
export class Address extends Entity {
@property({
type: 'string',
required: true,
})
city: string;
@property({
type: 'string',
required: true,
})
country: string
@property({
type: 'string',
required: true,
})
county: string;
@property({
type: 'string',
required: true,
})
state: string;
@property({
type: 'boolean',
required: true,
})
zipCode: boolean;
constructor(data?: Partial<Address>) {
super(data);
}
}
export class BaseModel extends CardAcceptor {
@property.array(CardAcceptor)
cardAcceptor: CardAcceptor;
@property({
type: 'string',
required: true,
})
destinationCurrencyCode: string;
@property({
type: 'string',
required: true,
})
markUpRate: string
@property({
type: 'string',
required: true,
})
retrievalReferenceNumber: string;
@property({
type: 'string',
required: true,
})
sourceAmount: string;
@property({
type: 'boolean',
required: true,
})
sourceCurrencyCode: boolean;
@property({
type: 'array',
itemType: 'string',
default: [],
})
systemsTraceAuditNumber?: string[];
constructor(data?: Partial<Game>) {
super(data);
}
}
希望这会有所帮助。谢谢