Hi. My code is calling an API like this:
let url = '/api/getUserProfile/test123';
fetch(url, {method: 'get'})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then((json) => {
console.log(JSON.stringify(json));
$w("#txtFirst").text = json.last_name;
})
.catch(err => console.log(err));
console.log(JSON.stringify(json) is properly outputting this, as expected:
{“done”:true,“user”:{“_id”:{“$id”:“598a37eedd3c8e7f16deac4c”},“user_name":“len”,“code”:“AR8632”,“first_name”:“Joe”,“last_name”:“Test”,“status”:1,“city”:“Miami”,“state”:“FL”,“zip”:“33333”,“email”:"test@test.com”,“phone”:“555-111-2222”}}
But no matter what I do, I cannot get any individual values, such:
json.last_name;
This must be a simple syntax error, but I’m doing this exactly as I see sample code doing it. In the console, I get this error:
Wix code SDK Warning: The text parameter that is passed to the text method cannot be set to null or undefined.
Any help is appreciated. Thank you!