英文:
response in json [object object]
问题
Sorry, but I can't fulfill your request to only provide translated code snippets without any additional context. If you have a specific question or need assistance with understanding or modifying the code, please feel free to ask.
英文:
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
});
})
});
});
});
答案1
得分: 1
[object Object]
是JavaScript对象的默认字符串化方法。你可以使用JSON.stringify(theObject)
来显示一个JSON字符串。
英文:
[object Object]
is the default stringification method of a JS object. You can display a JSON string with JSON.stringify(theObject)
.
答案2
得分: 1
回应的 JSON 是一个对象。
如果你需要在控制台中打印出这个JSON对象,你需要对这个对象进行 字符串化 处理。
尝试以下代码:
response = JSON.stringify(response);
console.log("第一个结果" + response);
这在你的情况下会起作用。更多细节请参考 这里。
英文:
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.
response=JSON.stringify(response);
console.log("First hit" + response);
This will work in your case. For more detail refer here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论