Search code examples
reactjsjsonnative

How to parse child item in react native?


<View style={{ flexDirection: 'row' }}>
<AntDesign name="flag" size={12} color="black" style={{ marginTop: 3, marginRight: 10 }} />
<Text style={styles.H1}>{item.name}</Text>
 <Text style={styles.H2}>{item.location}</Text>
 </View>

item is correctly parsing json name. But I've two items in location {flag:'', country:''}

How I could parse these two items in above code.


Solution

  • if you are trying to render the location then you can try this provided location is an object with flag and country as properties of location

    <View style={{ flexDirection: 'row' }}>
          <AntDesign name="flag" size={12} color="black" style={{ marginTop: 
         3, marginRight: 10 }} />
         <Text style={styles.H1}>{item.name}</Text>
         <Text style={styles.H2}>{item.location.country} </Text>
         <Text style={styles.H2}>{item.location.flag} </Text>
    </View>