0

am trying to access nested json array and display value in ,i can display all other json data in rowData and textfields but i cant display the one that has nested array.

this is my json

[
  {
    Address: "Njjzjjz",
    created_at: "2018-08-17 23:55:43",
    email: "Helen",
    gender: "Female",
    id: 24,
    name: "Helen",
    password: "$2y$10$.0fahBOp94ABqY6NTDf9S.9w880dsMRS.0azq4wAiB6evOxSxFAfC",
    phone: "9997",
    profile_pic: ["ec9bbcd6df212029715a34fe825e8616.jpeg", "1960.png"],
    remember_token: null,
    state_of_origin: "Akwa Ibom",
    state_of_resident: "Abia",
    updated_at: "2018-08-17 23:55:43"
  }
  // More Objects are here
 ]
I have issue with profilepic

and this is how i display it in rowdata

 <View style={styles.MainContainer}>

   <ListView

     dataSource={this.state.dataSource}

     renderSeparator= {this.ListViewItemSeparator}

     renderRow={(rowData) =>

    <View style={{flex:1}}>

    <Image source={{uri:'http://192.168.43.71/upload/images/'+rowData.profile_pic[0]  // this is my problem}}
   style={{width: 400, height: 400}} />
    {this.test()}

      <Text onPress={this.GetItem.bind(this, rowData.email)} style={styles.textViewContainer} >{rowData.email}</Text>
      <Text onPress={this.GetItem.bind(this, rowData.password)} style={styles.textViewContainer} >{rowData.profile_pic[0]}</Text>
       <Text onPress={this.GetItem.bind(this, rowData.email)} style={styles.textViewContainer} >{this.state.photos[0]}</Text>

    </View>
     }
   />
Mohammed Ashfaq
  • 3,353
  • 2
  • 15
  • 22
Obyno Pac
  • 103
  • 2
  • 13

1 Answers1

0

I think you need to set the width and height for the image.

 <Image 
  source={{uri: "http://192.168.43.71/upload/images/" + rowData.profile_pic[0]}} 
  style={{width:100, height:100}}
  resizeMode="cover"
/>

You can choose from from different resize mode option depend on your requirment.

For more details check here:
support Link
official documentation

Mohammed Ashfaq
  • 3,353
  • 2
  • 15
  • 22
  • yes the url is correct, and i can display other json data,the problem is i cant access the data in profile_pic[], it displays as arrays and when i use rowData.profile_pic[0] i get "[" on the console and if i use rowData.profile_pic[1] i get " " " on the console, if i use rowData.profile_pic[2] i get "e" on the console – Obyno Pac Aug 24 '18 at 15:49
  • I think in your json object the profile_pic is string not an Array. so when you try to print the profile_pic[0] it is retuning first character of string. – Mohammed Ashfaq Aug 24 '18 at 16:11
  • Declare your profilePic like this profile_pic: ["ec9bbcd6df212029715a34fe825e8616.jpeg", "1960.png"],. Not as you have copied first time in question – Mohammed Ashfaq Aug 24 '18 at 16:43