我有以下axios
获取请求:
export function getCurrentCart() {
return axios.get(Constants.ENDPOINT_MENU_TIMESLOTS, getConfig())
.then(res => {
let data = (res as AxiosResponse).data;
if (data != null) {
// parsing logic to singleton CartStore instance here
...
} else {
console.error("data is null");
}
});
}
检索ts CartStore
类:
export class CartStore {
id: number;
temporaryTotal: number;
status: string = "SHOPPING";
statusLockTime?: any;
updatedAt?: string;
createdAt?: string;
coupon?: Coupon;
readonly items = observable.shallowArray<CartItem>([]); // this is a mobx observable
@computed get hasItem(): boolean {
return this.items.length > 0;
}
@action clear() {
this.items.clear();
}
}
其中Coupon
和CartItem
是其他模型类。
以下是JSON响应示例:
{
"createdAt": "2017-02-16T20:37:13",
"updatedAt": "2017-02-22T22:48:50",
"id": 1,
"status": "SHOPPING",
"statusLockTime": null,
"temporaryTotal": 0,
"items": [
... array of some other json object
],
"coupon": {
... json object
}
}
你们推荐哪些deserializer librar(ies)?另一个问题是:如何在不使用任何库的情况下以最TS方式进行操作?