Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

JSON response cannot extract variables

$
0
0

Brand new to react-native and typescript!I'm have a bit of trouble extracting JSON response. I was to extract the response and put it into a class as shown below.

Here is the request code

    let notifications: INotification[]    notifications = (await Requests.GET('notification/user/test-user-1', accessToken));

Here is the class

      export interface INotification {          id: string;          senderId: string;          receiverId: string;          text: string;          isSeen: boolean;          type: string;          timestamp: string;      }

Here is the Postman response

{"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        }    ]}

Here is response from the console

  { 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 } ] }

I want to be able to write out:

console.log("TEXT: ",notifications[0].text )

And get the response of : "Text: Test notifications"

Any help welcome!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>