-
Anonymous
Извлечение информации из ответа JSON
Сообщение
Anonymous »
Я пытаюсь получить последнее значение «TMiles» в следующем JSON.
Код: Выделить всё
[{
"__type": "MileageReport:http:\/\/pcmiler.alk.com\/APIs\/v1.0",
"RouteID": null,
"ReportLines": [{
"Stop": {
"Address": {
"StreetAddress": "Apple Park Way",
"City": "Cupertino",
"State": "CA",
"Zip": "95014",
"County": "Santa Clara",
"Country": "United States",
"SPLC": null,
"CountryPostalFilter": 0,
"AbbreviationFormat": 0,
"StateName": "California",
"StateAbbreviation": "CA",
"CountryAbbreviation": "US"
},
"Coords": {
"Lat": "37.334866",
"Lon": "-122.014282"
},
"Region": 4,
"Label": "",
"PlaceName": "",
"TimeZone": "PDT",
"Errors": [],
"SpeedLimitInfo": null,
"ConfidenceLevel": "Exact",
"DistanceFromRoad": 0,
"CrossStreet": null,
"TimeZoneOffset": "GMT-7:00",
"TimeZoneAbbreviation": "PDT",
"IsDST": true
},
"LMiles": "0.000",
"TMiles": "0.000",
"LCostMile": "0.00",
"TCostMile": "0.00",
"LHours": "0:00",
"THours": "0:00",
"LTolls": "0.00",
"TTolls": "0.00",
"LEstghg": "0.0",
"TEstghg": "0.0",
"EtaEtd": null
}, {
"Stop": {
"Address": {
"StreetAddress": "22-26 West 34th Street",
"City": "New York",
"State": "NY",
"Zip": "10001",
"County": "New York",
"Country": "United States",
"SPLC": null,
"CountryPostalFilter": 0,
"AbbreviationFormat": 0,
"StateName": "New York",
"StateAbbreviation": "NY",
"CountryAbbreviation": "US"
},
"Coords": {
"Lat": "40.748462",
"Lon": "-73.984770"
},
"Region": 4,
"Label": "",
"PlaceName": "",
"TimeZone": "EDT",
"Errors": [],
"SpeedLimitInfo": null,
"ConfidenceLevel": "Exact",
"DistanceFromRoad": 0.003,
"CrossStreet": null,
"TimeZoneOffset": "GMT-4:00",
"TimeZoneAbbreviation": "EDT",
"IsDST": true
},
"LMiles": "2945.142",
"TMiles": "2945.142",
"LCostMile": "5690.99",
"TCostMile": "5690.99",
"LHours": "55:44",
"THours": "55:44",
"LTolls": "284.55",
"TTolls": "284.55",
"LEstghg": "9788.0",
"TEstghg": "9788.0",
"EtaEtd": null
}],
"TrafficDataUsed": false
}]
Я пробовал использовать несколько методов, но безрезультатно. Вот что я попробовал:
Код: Выделить всё
dataM = 'supplied json
var lastTMiles = dataM[0].ReportLines[dataM[0].ReportLines.length - 1].TMiles;
Вот моя ошибка:
Код: Выделить всё
Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at reqhttpM.onreadystatechange (mileage-finder.asp:280:60)
Я не совсем понимаю, что здесь делать. Ждем ответов. Спасибо
Подробнее здесь:
https://stackoverflow.com/questions/790 ... n-response
1729047928
Anonymous
Я пытаюсь получить последнее значение «TMiles» в следующем JSON.
[code][{
"__type": "MileageReport:http:\/\/pcmiler.alk.com\/APIs\/v1.0",
"RouteID": null,
"ReportLines": [{
"Stop": {
"Address": {
"StreetAddress": "Apple Park Way",
"City": "Cupertino",
"State": "CA",
"Zip": "95014",
"County": "Santa Clara",
"Country": "United States",
"SPLC": null,
"CountryPostalFilter": 0,
"AbbreviationFormat": 0,
"StateName": "California",
"StateAbbreviation": "CA",
"CountryAbbreviation": "US"
},
"Coords": {
"Lat": "37.334866",
"Lon": "-122.014282"
},
"Region": 4,
"Label": "",
"PlaceName": "",
"TimeZone": "PDT",
"Errors": [],
"SpeedLimitInfo": null,
"ConfidenceLevel": "Exact",
"DistanceFromRoad": 0,
"CrossStreet": null,
"TimeZoneOffset": "GMT-7:00",
"TimeZoneAbbreviation": "PDT",
"IsDST": true
},
"LMiles": "0.000",
"TMiles": "0.000",
"LCostMile": "0.00",
"TCostMile": "0.00",
"LHours": "0:00",
"THours": "0:00",
"LTolls": "0.00",
"TTolls": "0.00",
"LEstghg": "0.0",
"TEstghg": "0.0",
"EtaEtd": null
}, {
"Stop": {
"Address": {
"StreetAddress": "22-26 West 34th Street",
"City": "New York",
"State": "NY",
"Zip": "10001",
"County": "New York",
"Country": "United States",
"SPLC": null,
"CountryPostalFilter": 0,
"AbbreviationFormat": 0,
"StateName": "New York",
"StateAbbreviation": "NY",
"CountryAbbreviation": "US"
},
"Coords": {
"Lat": "40.748462",
"Lon": "-73.984770"
},
"Region": 4,
"Label": "",
"PlaceName": "",
"TimeZone": "EDT",
"Errors": [],
"SpeedLimitInfo": null,
"ConfidenceLevel": "Exact",
"DistanceFromRoad": 0.003,
"CrossStreet": null,
"TimeZoneOffset": "GMT-4:00",
"TimeZoneAbbreviation": "EDT",
"IsDST": true
},
"LMiles": "2945.142",
"TMiles": "2945.142",
"LCostMile": "5690.99",
"TCostMile": "5690.99",
"LHours": "55:44",
"THours": "55:44",
"LTolls": "284.55",
"TTolls": "284.55",
"LEstghg": "9788.0",
"TEstghg": "9788.0",
"EtaEtd": null
}],
"TrafficDataUsed": false
}]
[/code]
Я пробовал использовать несколько методов, но безрезультатно. Вот что я попробовал:
[code]dataM = 'supplied json
var lastTMiles = dataM[0].ReportLines[dataM[0].ReportLines.length - 1].TMiles;
[/code]
Вот моя ошибка:
[code]Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at reqhttpM.onreadystatechange (mileage-finder.asp:280:60)
[/code]
Я не совсем понимаю, что здесь делать. Ждем ответов. Спасибо
Подробнее здесь: [url]https://stackoverflow.com/questions/79092312/extracting-info-from-json-response[/url]