【发布时间】:2014-12-09 01:17:35
【问题描述】:
我有一个从 QuickBooks Online API 返回的大型 JSON 对象。它是有效的 JSON 并显示在控制台上(在记录之后)。
在检查控制台时,我看到以下内容:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
可以扩展为:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
1: Object
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object
10: Object
11: Object
12: Object
13: Object
14: Object
15: Object
16: Object
17: Object
18: Object
19: Object
20: Object
21: Object
22: Object
23: Object
24: Object
length: 25
__proto__: Array[0]
0: Object 扩展为:
0: Object
*_data: Object
$$hashKey: "object:82"
__proto__: Object
*_data: Object 扩展为:
Active: Array[1]
Balance: Array[1]
BalanceWithJobs: Array[1]
BillAddr: Array[1]
BillWithParent: Array[1]
DisplayName: Array[1]
FamilyName: Array[1]
Fax: Array[1]
FullyQualifiedName: Array[1]
GivenName: Array[1]
Id: Array[1]
Job: Array[1]
MetaData: Array[1]
Mobile: Array[1]
PreferredDeliveryMethod: Array[1]
PrimaryEmailAddr: Array[1]
PrimaryPhone: Array[1]
PrintOnCheckName: Array[1]
SalesTermRef: Array[1]
SyncToken: Array[1]
Taxable: Array[1]
我正在尝试访问名为 DisplayName 的属性。
用于控制台记录 json 数据的 Angular 代码:
$http.get('/customer').success(function(customers) {
$scope.customers = customers;
console.log($scope.customers[0]["*_data"].DisplayName[0]);
});
如何做到这一点?可以在控制台中输入一些东西来返回它的值吗?
更新:
我可以使用以下方法访问对象:
console.log($scope.customers[0]);
但是,*_data 是一个对象。我在想这样的事情:
console.log($scope.customers[0].*_data); 可以,但是我收到错误:
Uncaught SyntaxError: Unexpected token *.
【问题讨论】:
-
你能用括号表示吗?喜欢
<thisjson>[0]["*_data"]["DisplayName"];? -
@brbcoding,我在尝试时收到此错误:
Uncaught SyntaxError: Unexpected token <没有括号,thisjson未定义。 -
brbcoding 并不意味着要按字面意思使用
<thisjson>,只是用作存储 json 的任何变量的占位符。 -
RaphaelRafatpanah @chazsolo 说了什么。
-
啊。
console.log($scope.customers[0]);在控制台中返回object。如何访问对象?console.log($scope.customers[0]["*_data"]);返回未定义。
标签: javascript json