0

Below is the JSON response:

{
    "status": "passedd",
    "reasons": {
        "welcome": {
            12: "helo",
            14: "hi",
            15: "fine",
            14: "Not interested"
        },
        "speakin": {
            16: "Phone",
            19: "Msg",
            21: "Whatssup"
        },
        "Byee": {
            17: "Gud bye",
            25: "Need help",
            26: "byeee",
            27: "Help"
        }
    }
}

I need to access the value of the object eg:Helo. Since I'm a newbie to react native I'm not clear in accessing the object values.

Using Objects.keys(reasons) I'm able to get welcome, speakin,Byee. How to access the keys and values under that? Please help me.

ADyson
  • 57,178
  • 14
  • 51
  • 63
DDM
  • 113
  • 1
  • 17
  • 1
    I'd recommend reading through a basic JavaScript tutorial on objects; if you can't do this, working effectively with React will be very difficult. – jonrsharpe Jul 24 '18 at 12:54
  • "I'm able to get welcome, speakin,Byee"...ok and what's the problem with accessing the ones below it? What code did you use? What went wrong? BTW this is just going to be basic JS, no requirement for React. Possibly you should read this: https://stackoverflow.com/questions/16908476/object-property-name-as-number – ADyson Jul 24 '18 at 14:35

1 Answers1

0

Try this

 fetch(.....)
        .then(res => res.json())
        .then((responseJson) => {
            welcome = responseJson.reasons.welcome
            helo = welcome.12
        })
        .catch((error) => {
          .....
        });
}
Jay Thummar
  • 2,281
  • 1
  • 14
  • 22