为什么我得到的输出是“\”userName\”” 而不是“userName”?

希拉

为什么我得到输出"\"userName\""而不是那样"userName"在我的例子中,我尝试做一个 get api,将一些数据附加到它上面,这些数据来自异步存储。当我控制台输出时,它会显示这样的数据:

"\"userName\""

但它应该输出"userName". 解决这个问题的方法是什么?

那么我的方式有什么问题呢?

const getSaveUserTokenData = async (data) => {
    const url =
      'https://URL/userName,userToken,PlatformType,DeviceID?' +
      'userName=' +
      data.userName +
      '&userToken=' +
      data.googlToken +
      '&PlatformType=' +
      data.platformId +
      '&DeviceID=' +
      data.deviceId;
    await fetch(
      url,

      {
        method: 'GET',
        headers: {
          Authorization: data.azureToken,
        },
      }
    )
      .then((response) => response.json())
      .then((data) => {
        console.log('Success:', data);
      })
      .catch((error) => {
        console.error('Error:', error);
      });
  };
沙纳瓦兹·侯桑

你也可以这样写:

fetchFunction = async () => {

    let data = {
        userName: 'jon',
        userToken: 'bee22',
        PlatformType: 'os-ios',
        DeviceID: '222222'
    }


    const url = `https://yoururl.com/?userName=${encodeURIComponent(data.userName)}&userToken=${encodeURIComponent(data.userToken)}&PlatformType=${encodeURIComponent(data.PlatformType)}&DeviceID=${encodeURIComponent(data.DeviceID)}`;


    const response = await fetch(url, {
        method: 'GET',
        headers: {
            'Authorization': 'Basic ' + btoa('username:password'),
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
    });

    const json = await response.json();

    console.log(json);

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过userName而不是userId添加keyCloak用户角色

为什么我得到“ mergeCursor”对象而不是“ string”?

“ Domain / MachineName $”用于身份验证,而不是“ Domain / UserName”

为什么我得到* ngIf不是div错误的属性?

User.Identity.Name返回UserName而不是Name

未定义不是对象(评估“ this.state.username”)

为什么$ username变量在if($ username = request('createdBy')){{

即使ApplicationUserId不是,ApplicationUser.Username也为null

为什么我得到一个线程而不是参数?

为什么我得到承诺而不是价值?

为什么我得到[object object]而不是JSON?

为什么$ env:username和[environment] :: username返回不同的用户?

为什么我得到AggregationCursor而不是平均值?

为什么我得到的是整数而不是数组?

如何在终端而不是username @ hostname中显示时间?

为什么在分叉后我得到0而不是1?

为什么我得到未定义的不是函数?

为什么我得到“字符串不是函数”?

为什么我得到“ popq%rbp”而不是“ leave”?

提供文件路径时,为什么不能使用'〜'而不是'/ home / username /'

为什么我得到这个“ res.render()不是函数”

为什么“ sudo ls〜”显示/ home / username而不是/ root的内容?

为什么我在 CSS Grid 中得到的是列而不是行?

为什么我使用 JQuery 得到的只是文本而不是 HTML?

为什么我得到零而不是 1?

为什么我得到无限循环而不是异常?

为什么我得到的是 .aab 文件而不是 .apk 文件?

为什么我得到的是字母“e”而不是我给它的值?

为什么我得到错误的输出 2686924 而不是 281?