javascript - json 响应 Angular 2 中的错误字符

标签 javascript json angular

我从外部 API 检索了 JSON 响应,其中一个变量名称以 # 字符开头,因此 JSON 变量类似于 #text。不幸的是, Angular 不知道如何处理这个变量,有什么办法删除 # 以便分配给标识符的数据可用。 JSON response with #text identifier

最佳答案

为了引用不遵循正确格式规则的属性 identifier ,对于 property accessor 必须使用方括号表示法而不是点表示法。 :

var object = JSON.parse('{"#text":"https://lastfm-im...png","size":"extralarge"}')
console.log(object['#text'])

关于javascript - json 响应 Angular 2 中的错误字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261910/

相关文章:

javascript - 寻求澄清;如何使用本地文件和 Ajax 访问特定的 Web 服务

ios - Devise with Facebook Omniauth - 如何使用 API 进行身份验证?

javascript - 无法专注于 Angular @ng-select 中的自定义提交按钮

javascript - Ext 或 Ext_scaffold 中的 bool 字段已损坏?

JavaScript 循环遍历所有带有标记名、警报的元素

json - JQuery Grid-SubGrid 用于父子关系

javascript - Vue.js - 将 JSON 对象写入本地文件

angular - ./node_modules/bootstrap/dist/css/bootstrap.css 中的错误

javascript - Ionic 3 App - 使用非 ionic html 组件的最佳方式

javascript - 我需要在中间件中使用 `next` 或 `store.dispatch`