A
A
Alexey2021-12-15 08:00:41
JSON
Alexey, 2021-12-15 08:00:41

How to output JSON result in React Native?

Hello, I have a json response like this

{
    "eduGroups": [
        {
            "id": 1832256972789086426,
            "id_str": "1832256972789086426",
            "parentIds": [],
            "parentIds_str": [],
            "type": "Group",
            "fullName": null,
            "parallel": 2,
            "timetable": 275789787685443,
            "timetable_str": "275789787685443",
            "status": "Active",
            "studyyear": 2021,
            "subjects": null,
            "journaltype": "Classical"
        }
    ],
 "splitId": "NotSet",
    "personId": 1000018246635,
    "shortName": "Алексей А",
    "schoolIds": [
        53330
    ]
}


I need to display the string shortName, but it is not displayed. But the line with data about "studyyear", it displays.

<code> const getData = async () => {
      try {
       const response = await fetch('https://api.dnevnik.ru/v2/users/me/context',{
        method : 'POST',
        headers: {
          'Access-Token' : token
        }
    })
        const json = await response.json();
        setData(json);
      } catch (error) {
        console.error(error);
      } finally {
        setLoading(false);
      }
    }

    useEffect(() => {
      getData();
    }, []);</code>
    return (
      <View style={styles.container}>
        {isLoading ? <ActivityIndicator/> : (
        <FlatList
          data={data}
          renderItem={({ item }) => (
            <Text>{item.schools.name}, {item.releaseYear}</Text>
          )}
        />
      )}
        <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
      </View>
    );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question