我正在尝试编写一个循环来直接访问这个 json 数组的元素,我在这里和其他地方使用了一些示例,这些示例显示了 json 数据的迭代,但是我在使用索引的同时没有任何工作.
我一直在寻找在一个循环中执行以下操作,实际上我的 json 在一行上(参见 jsfiddle):
alert(jsonData.data[0].serviceType);
可读的json字符串
{
"data": [{
"id": "1",
"serviceType": "test",
"firstName": "",
"lastName": "",
"address1": "",
"address2": "",
"address3": "",
"city": "",
"county": "",
"postCode": "",
"website": "",
"latitude": "",
"longitude": "",
"phoneArr": ["00001", "000002"]
}, {
"id": "1",
"serviceType": "",
"firstName": "",
"lastName": "",
"address1": "",
"address2": "",
"address3": "",
"city": "",
"county": "",
"postCode": "",
"website": "",
"latitude": "",
"longitude": "",
"phoneArr": ["00001", "000002"]
}]
}