我是混合离子应用程序开发的初学者。我想在我的项目中实现 RESTful Web 服务。 我的 json 数据是:
{
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Antonio Moreno Taquería",
"City": "México D.F.",
"Country": "Mexico"
}]
}
在这里,我想在 ionic 中的列表视图中解析此数据。我不知道如何使用数组解析数据。请建议解决方案或教程以获得结果。我想在列表视图中显示所有名称。 我正在使用这个 api 链接:http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt 提前谢谢。
在这里,您无需解析 JSON 数据,它已经是对象格式。
你可以这样使用
var myData = {
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Antonio Moreno Taquería",
"City": "México D.F.",
"Country": "Mexico"
}]
}
var record1 = myData.records[0];
var record2 = myData.records[1];
var record3 = myData.records[2];
console.log(record1)
console.log(record2)
console.log(record3)
console.log("Record 1 Data:")
console.log('t'+"Name: "+record1.Name)
console.log('t'+"City: "+record1.City)
console.log('t'+"Country: "+record1.Country)
console.log("Record 2 Data:")
console.log('t'+"Name: "+record2.Name)
console.log('t'+"City: "+record2.City)
console.log('t'+"Country: "+record2.Country)
console.log("Record 3 Data:")
console.log('t'+"Name: "+record3.Name)
console.log('t'+"City: "+record3.City)
console.log('t'+"Country: "+record3.Country)