简体   繁体   中英

casting of JSON to typeScript class in Angular2

在此处输入图片说明

How to convert this JSON structure to Class

You can use JSON2TS which will automatically create a typescript class for you.

Just paste the JSON and see the corresponding ts file.

Looking at your screenshot, you can declare it by using this:

declare module namespace {

    export interface Address {
        city?: any;
        area?: any;
        house_No?: any;
        landmark?: any;
        locality?: any;
    }

    export interface Order {
        product_Name: string;
        product_ID: string;
        order_Active: boolean;
        price: string;
        qty: string;
    }

    export interface OrderList {
        address: Address;
        order: Order[];
        order_ID: string;
        timeStamp: number;
        total_Amount: number;
        user_ID: string;
    }

    export interface RootObject {
        orderList: OrderList[];
        orderSize: number;
        status_code: string;
        status_message: string;
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM