1
我有一個Person類,並在設置其屬性後,找出將該類轉換爲json對象的最佳方法。從Typscript類創建JSON對象
class Person {
firstName: string;
lastName: string;
}
let person = new Person();
person.firstName = "FirstName";
person.lastName = "LastName";
,如果我做person.getJson()也應該給JSON對象下面
{
"firstName": "FirstName",
"lastName": "LastName"
}
視爲給定的櫃面lastName的也不會設置JSON對象應該只有的firstName
{
"firstName": "FirstName"
}