响应中的 JSON [object object]

huangapple go评论63阅读模式
英文:

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

响应中的 JSON [object object]

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

huangapple
  • 本文由 发表于 2023年4月6日 20:38:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949620.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定