首页 > 解决方案 > 在打字稿上反序列化数组数据的问题(React-native)

问题描述

我需要将我的数据数组解析为 myModel[]。

这是数据加载:

    export function getMockFAQ() {
return [
    {
        title: "FAQ Question 1"
    },
    {
        title: "FAQ Question 1"
    },
    {
        title: "FAQ Question 1"
    }
]
}

我的模型:

export interface FAQInterface {
title: string;
}

如何将此数据转换为 FAQInterface[] ?

const data = getMockFAQ();

标签: typescriptparsing

解决方案


好简单kkkkkk

  export function getMockFAQ(): FAQInterface[] {
return [
{
    title: "FAQ Question 1"
},
{
    title: "FAQ Question 1"
},
{
    title: "FAQ Question 1"
}
]
}

推荐阅读