我有一个带有多个嵌套数组和对象的对象的json文件,我很难找到一种迭代它并获取所有数据的方法,因为属性嵌套在各种'位置'在对象内。我试图简化对象并希望它不会太大:
{
"trips": [{
"trains": {
"originTrains": {
"originTrain": [{
//always 2 x trainSegment - 1 for train to location and return train
"trainSegment": [{
//unknown numbers of objects inside trainSegment array
"Departure": {
"Location": "xxx"
},
"Arrival": {
"Location": "yyy"
},
"duration": 195,
}, {
"Departure": {
"Location": "yyy"
},
"Arrival": {
"Location": "zzz"
},
"duration": 240,
}],
"duration": 485
}, {
"trainSegment": [{
"Departure": {
"Location": "zzz"
},
"Arrival": {
"Location": "mmm"
},
"duration": 160,
}, {
"Departure": {
"Location": "mmm"
},
"Arrival": {
"Location": "xxx"
},
"duration": 325,
}],
"duration": 745
}]
},
"Direction": "Return"
},
"PriceInfo": {
"Breakdown": {
"FareBreakdown": {
"PassengerQuantity": {
"Quantity": 1,
"Code": "ABC"
},
"Endorsements": {
"NotRefundable": true
}
}
},
"FareInfos": {
"FareInfo": [{
"Extensions": {
"SeatsRemaining": {
"BelowMinimum": false,
"Number": 4
}
}
}]
},
"Fare": {
"TotalFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": 341.61
},
"Taxes": {
"Tax": [{
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"TaxCode": "TOTALTAX",
"Amount": 66.25
}]
},
"BaseFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": 275.36
}
}
},
"TicketingInfo": {
"TicketType": "eTicket"
}
}, {
"trains": {
"originTrains": {
//all over again
}
最终我想要显示所有信息(作为所有列车的出发地,目的地,时间,持续时间。到目前为止我尝试过的任何东西都没有真正起作用。我没有提供我的代码作为我的所有循环没有意义,没有工作,但当然可以提供。任何帮助都将非常感谢。谢谢。