Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams { key: 1, label: 'Service1'}, { key: 2, label: 'Service2' }, { key: 3, label: 'Service3' }, { key: 4, label: 'Service4' }, { key: 5, label: 'Service4' },

and json data:

 "services": [
      "id": 1,
      "name": "Hotels",
      "id": 2,
      "name": "Embassies",

How to map id to key and name to label???

HI @SandhyaDesmukh, welcome to StackOverflow. Thanks for contributing your first answer! However, I think you have a little typo on jsonData. Since that jsonData variable is not a valid array. Fix that up and I'll vote you up :) – Irfandy Jip Dec 19, 2019 at 6:42

i know it to much late,but i hope its helpfull for others,How to fetch the response of JSON array in react native?How to map json data with array in react native

export default class ExpenseNew extends Component {
    constructor(){
        super();
        this.state={
            PickerSelectedVal : '',
            accountnameMain:[],
     componentDidMount(){
         var account_nam=[]
                fetch('your Url', {
                    method: 'GET',
                    headers: { 'Authorization': 'Bearer ' + your token }
                    .then((response) => response.json())
                    .then((customerselect) => {
                        // alert(JSON.stringify(customerselect)) 
                        global.customerdata = JSON.stringify(customerselect)
                        var customername = JSON.parse(customerdata);
                        //alert(JSON.stringify(customername));
                        for (i = 0; i < customername.cus_data.length; i++) {
                            var dataa = customername.cus_data[i]["account_name"];  
                            account_nam.push(dataa)
                        this.setState({accountnameMain:account_nam});
                    .done();
                    render() {
                          return (
                               <Picker
                                selectedValue={this.state.PickerSelectedVal}
                                placeholder="Select your customer"
                                mode="dropdown"
                                iosIcon={<Icon name="arrow-down" />}
                                onValueChange={(itemValue, itemIndex) => this.setState({PickerSelectedVal: itemValue})} >
                                {this.state.accountnameMain.map((item, key)=>(
                                    <Picker.Item label={item} value={item} key={key}/>)
                            </Picker>

the above example is fetch array of data from json,and map data in to dropdown/picker,i hope its helpfull for others,if you have any query, asked from me

The author asked for a simple mapping. This has nothing to do with the question and could be written with half the lines of code. – Pawel Dec 16, 2019 at 8:10 yes i understand,but its a complete example,our author understand more clearly,but you are right – Aakash Sajjad Dec 16, 2019 at 8:20

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.