Component - JSON response parsing
This React Native component fetches data from a JSON API and shows a list of items on the screen. It parses the JSON response and updates the UI with the data.
This React Native component fetches data from a JSON API and shows a list of items on the screen. It parses the JSON response and updates the UI with the data.
View ├─ Text (Title) ├─ FlatList │ └─ renderItem: View > Text └─ Button (Refresh)
response.json() do in React Native when fetching data?response.json() method reads the raw response and converts it into a usable JavaScript object.response.json(), which returns a promise with the parsed object.fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data.name))
.catch(error => console.error(error));{"name": "Alice", "age": 25}?data.name, which is "Alice".fetch('https://api.example.com/data')
.then(response => response.json)
.then(data => console.log(data))
.catch(error => console.error(error));response.json without parentheses, so it references the function but does not call it.response.json() to actually parse the JSON.{"users": [{"id": 1, "name": "Bob"}, {"id": 2, "name": "Carol"}]}data.users.map(user => user.name) which creates a new array of names.Pass the test and this pattern moves unknown