Below is my code to get response from webapi i am able to get results as count is showing right but it coming in [object object] format how to get proper json below is my line of code
const userList: ISuggestionItem[]=[];
this.props.context.aadHttpClientFactory
.getClient('xxxxxx-xxx-xxx-xxx-xxxx')
.then((client: AadHttpClient): void => {
client
.get('https://xxxxx.azurewebsites.net/api/xxxxxx?userEmail=xxxxx.onmicrosoft.com', AadHttpClient.configurations.v1)
.then((response:HttpClientResponse)=> {
console.log("First hit" + response)
response.json().then((responseJSON: any) => {
console.log("Second hit" + responseJSON.stringify)
responseJSON.map(function(item:any) {
console.log("third hit" + item.stringify)
userList.push({
"key" : item.Test1,
"displayValue" : item.Test2,
"searchValue": item.Test3
});
})
});
});
});
2
Answers
[object Object]
is the default stringification method of a JS object. You can display a JSON string withJSON.stringify(theObject)
.The response JSON is an object.
If you need to print the JSON object in console, you need to stringify the object.
Try the below code.
This will work in your case. For more detail refer here