title: react native json response check if string or object
body: <p>sorry for the silly question. I am relatively new to react native. I have got fetch working so I can get the json response back from the server. The server API returns a string if there is an error or returns an json object if its successful. is there any way to compare the response to see if its a string or json variable? </p>
  
  <p>Not sure how to achieve the above any help would be appreciated. </p>
  
  <p>here is my code</p>
  
  <p>API.js</p>
  
  <pre><code>var API = {
  
     SetupBuyOnline(email, serialNumber, platformType) {
          var url = 'https://&lt;urlomitted&gt;/SetupBuyOnline';
          return fetch(url, {
              method: 'GET',
              headers: {
                  'Content-Type': 'application/json; charset=UTF-8',
                  'Accept': 'application/json',
                  'operating_system': platformType,
                  'email': email,
                  'serialNumber': serialNumber
              }
          }).then((res) =&gt; res.json());
      }
  };
  </code></pre>
  
  <p>find userScreen.js</p>
  
  <pre><code>  findUserScreen(){
      // this.props.navigation.navigate('JoinNowScreen')
      StudentApi.SetupBuyOnline('useremail@test.com', deviceId, "iOS")
      .then((responseData) =&gt; {
        if(typeof(responseData) == 'string')
        {
          console.log('got api call ' + responseData);
          alert('test = ' + responseData);
        }
        else
        {
          console.log('got api call ' + responseData);
          alert(responseData);
        }
      })
    }
  </code></pre>
  
  <p>Not sure what I am doing wrong. Thanks in advance</p>