【发布时间】:2021-02-10 15:28:55
【问题描述】:
react-native 和 typescript 的全新功能! 我在提取 JSON 响应时遇到了一些麻烦。我将提取响应并将其放入一个类中,如下所示。
这里是请求代码
let notifications: INotification[]
notifications = (await Requests.GET('notification/user/test-user-1', accessToken));
这是课程
export interface INotification {
id: string;
senderId: string;
receiverId: string;
text: string;
isSeen: boolean;
type: string;
timestamp: string;
}
这是邮递员的回复
{
"notifications": [
{
"pk": "user-1",
"sk": "notification1234",
"entity": "notification",
"id": "id number",
"senderId": "test-user-2",
"receiverId": "test-user-1",
"text": "Test notifications",
"isSeen": false,
"type": 2
}
]
}
这是来自控制台的响应
{ notifications:
[ { pk: 'user#test-user-1',
sk: 'notification1234',
entity: 'notification',
id: 'id number',
senderId: 'test-user-2',
receiverId: 'test-user-1',
text: 'Test notifications',
isSeen: false,
type: 2 } ]
}
我希望能够写出来:
console.log("TEXT: ",notifications[0].text )
并得到响应:“文本:测试通知”
欢迎任何帮助!
【问题讨论】:
-
您能否编辑问题,添加您当前正在尝试的内容、尝试的结果以及与您想要的结果有何不同?
标签: json typescript react-native react-native-android react-native-ios