Hej! Försöker göra en app med hjälp av Trafiklab. Får ett svar som jag försöker hämta delar av. Tycker det är svårt att plocka ut enskilda element.
Här är en URL som använder resrobot reseplanerare.
Just i detta anropet är det att hitta en resa mellan Malmö och Eslöv.
let TRAIN_URL = "https://api.resrobot.se/v2/trip?key=xxxxxxxxxxxxxxxxxxxxxxx&o..." //Sök mellan två platser
Någon som gjort detta eller liknande?
Nedan är ett exempel där jag hämtar ut en resa mellan Malmö och Eslöv.
Tycker dock det är svårt att plocka ut värden då det är nästlat och med Arrays.
Ett annat exempel där jag plockad värden från en enklare struktur som hade Array.
let tempResult = json["StopLocation"][2]["name"]
JSON-svar
"scrF" : "1|OF|MTµ11µ10583µ10583µ10607µ10607µ0µ0µ365µ10532µ6µ-2147482382µ0µ1µ2|PDHµ93f5d31ef3d8516eaa75437b0af8ef0b|RDµ23062019|RTµ5030",
"scrB" : "1|OB|MTµ11µ10373µ10373µ10400µ10400µ0µ0µ5µ10130µ1µ-2147482382µ0µ1µ2|PDHµ93f5d31ef3d8516eaa75437b0af8ef0b|RDµ23062019|RTµ5030",
"Trip" : [
{
"idx" : 0,
"LegList" : {
"Leg" : [
{
"Notes" : {
"Note" : [
{
"routeIdxFrom" : 2,
"value" : "Pågatågen",
"type" : "A",
"key" : "VG",
"priority" : 100,
"routeIdxTo" : 7
},
{
"routeIdxFrom" : 2,
"value" : "Endast 2 klass",
"type" : "A",
"key" : "AA",
"priority" : 100,
"routeIdxTo" : 7
},
{
"routeIdxFrom" : 2,
"value" : "Ej reservering",
"type" : "A",
"key" : "AE",
"priority" : 100,
"routeIdxTo" : 7
}
]
},
"Stops" : {
"Stop" : [
{
"lon" : 13.000909999999999,
"extId" : "740000003",
"routeIdx" : 2,
"lat" : 55.609456000000002,
"id" : "740000003",
"depTime" : "04:53:00",
"depDate" : "2019-06-23",
"name" : "Malmö Centralstation"
},
{
"name" : "Hjärup station (Staffanstorp kn)",
"lon" : 13.136512,
"extId" : "740000942",
"routeIdx" : 3,
"lat" : 55.674151000000002,
"id" : "740000942",
"depTime" : "05:00:00",
"arrDate" : "2019-06-23",
"arrTime" : "05:00:00",
"depDate" : "2019-06-23"
},
{
"name" : "Lund Centralstation",
"lon" : 13.186897,
"extId" : "740000120",
"routeIdx" : 4,
"lat" : 55.708094000000003,
"id" : "740000120",
"depTime" : "05:07:00",
"arrDate" : "2019-06-23",
"arrTime" : "05:05:00",
"depDate" : "2019-06-23"
},
{
"name" : "Stångby station (Lund kn)",
"lon" : 13.200201,
"extId" : "740000834",
"routeIdx" : 5,
"lat" : 55.751153000000002,
"id" : "740000834",
"depTime" : "05:11:00",
"arrDate" : "2019-06-23",
"arrTime" : "05:11:00",
"depDate" : "2019-06-23"
},
{
"name" : "Örtofta station (Eslöv kn)",
"lon" : 13.243969,
"extId" : "740000961",
"routeIdx" : 6,
"lat" : 55.778928999999998,
"id" : "740000961",
"depTime" : "05:15:00",
"arrDate" : "2019-06-23",
"arrTime" : "05:15:00",
"depDate" : "2019-06-23"
},
{
"lon" : 13.305491,
"extId" : "740000260",
"routeIdx" : 7,
"lat" : 55.837719,
"id" : "740000260",
"arrDate" : "2019-06-23",
"arrTime" : "05:20:00",
"name" : "Eslöv station"
}
]
},
"transportNumber" : "1252",
"direction" : "Höör station",
"Product" : {
"operator" : "Skånetrafiken",
"catCode" : "4",
"name" : "Länstrafik - Tåg 1252",
"operatorUrl" : "http:\/\/www.skanetrafiken.se",
"catOutL" : "Länstrafik - Tåg",
"operatorCode" : "276",
"catOutS" : "JLT",
"num" : "1252"
},
"Origin" : {
"time" : "04:53:00",
"lon" : 13.000909999999999,
"extId" : "740000003",
"routeIdx" : 2,
"lat" : 55.609456000000002,
"id" : "740000003",
"type" : "ST",
"date" : "2019-06-23",
"name" : "Malmö Centralstation"
},
"Destination" : {
"time" : "05:20:00",
"lon" : 13.305491,
"extId" : "740000260",
"routeIdx" : 7,
"lat" : 55.837719,
"id" : "740000260",
"type" : "ST",
"date" : "2019-06-23",
"name" : "Eslöv station"
},
"name" : "Länstrafik - Tåg 1252",
"idx" : "0",
"transportCategory" : "JLT",
"reachable" : true,
"type" : "JNY"
}
]
},
"ServiceDays" : [
{
"planningPeriodEnd" : "2019-08-18",
"sDaysB" : "FFFFFFFFFFFFFFFC",
"planningPeriodBegin" : "2019-06-18",
"sDaysR" : "daily"
}
],
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230453$201906230520$JLT 1252$$1$",
"tripId" : "C-0",
"duration" : "PT27M"
},
{
"idx" : 1,
"LegList" : {
"Leg" : [
{
"idx" : "0",
"reachable" : true,
"Stops" : {
"Stop" : [
{
"depTime" : "06:23:00",
"lon" : 13.000909999999999,
"id" : "740000003",
"depDate" : "2019-06-23",
"extId" : "740000003",
"lat" : 55.609456000000002,
"name" : "Malmö Centralstation",
"routeIdx" : 8
},
{
"depTime" : "06:30:00",
"lon" : 13.136512,
"id" : "740000942",
"depDate" : "2019-06-23",
"extId" : "740000942",
"arrTime" : "06:30:00",
"lat" : 55.674151000000002,
"routeIdx" : 9,
"arrDate" : "2019-06-23",
"name" : "Hjärup station (Staffanstorp kn)"
},
{
"depTime" : "06:37:00",
"lon" : 13.186897,
"id" : "740000120",
"depDate" : "2019-06-23",
"extId" : "740000120",
"arrTime" : "06:35:00",
"lat" : 55.708094000000003,
"routeIdx" : 10,
"arrDate" : "2019-06-23",
"name" : "Lund Centralstation"
},
{
"lon" : 13.305491,
"id" : "740000260",
"extId" : "740000260",
"arrTime" : "06:47:00",
"lat" : 55.837719,
"routeIdx" : 11,
"arrDate" : "2019-06-23",
"name" : "Eslöv station"
}
]
},
"transportNumber" : "1510",
"Destination" : {
"lon" : 13.305491,
"id" : "740000260",
"time" : "06:47:00",
"extId" : "740000260",
"lat" : 55.837719,
"date" : "2019-06-23",
"routeIdx" : 11,
"name" : "Eslöv station",
"type" : "ST"
},
"Product" : {
"operatorUrl" : "http:\/\/www.skanetrafiken.se",
"num" : "1510",
"catOutL" : "Länstrafik - Tåg",
"name" : "Länstrafik - Tåg 1510",
"catOutS" : "JLT",
"operatorCode" : "276",
"catCode" : "4",
"operator" : "Skånetrafiken"
},
"name" : "Länstrafik - Tåg 1510",
"Notes" : {
"Note" : [
{
"value" : "Pågatågen",
"key" : "VG",
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"routeIdxFrom" : 8
},
{
"key" : "AA",
"routeIdxFrom" : 8,
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"value" : "Endast 2 klass"
},
{
"key" : "AE",
"routeIdxFrom" : 8,
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"value" : "Ej reservering"
}
]
},
"transportCategory" : "JLT",
"Origin" : {
"lat" : 55.609456000000002,
"routeIdx" : 8,
"lon" : 13.000909999999999,
"time" : "06:23:00",
"name" : "Malmö Centralstation",
"id" : "740000003",
"type" : "ST",
"date" : "2019-06-23",
"extId" : "740000003"
},
"type" : "JNY",
"direction" : "Helsingborg Centralstation"
}
]
},
"ServiceDays" : [
{
"planningPeriodBegin" : "2019-06-18",
"planningPeriodEnd" : "2019-08-18",
"sDaysB" : "FFFFFFFFFFFFFFFC",
"sDaysR" : "daily"
}
],
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230623$201906230647$JLT 1510$$1$",
"tripId" : "C-1",
"duration" : "PT24M"
},
{
"idx" : 2,
"LegList" : {
"Leg" : [
{
"Product" : {
"catOutL" : "Länstrafik - Tåg",
"num" : "1405",
"operator" : "Skånetrafiken",
"catCode" : "4",
"name" : "Länstrafik - Tåg 1405",
"catOutS" : "JLT",
"operatorCode" : "276",
"operatorUrl" : "http:\/\/www.skanetrafiken.se"
},
"transportCategory" : "JLT",
"type" : "JNY",
"Notes" : {
"Note" : [
{
"routeIdxFrom" : 7,
"type" : "A",
"key" : "VG",
"priority" : 100,
"value" : "Pågatågen",
"routeIdxTo" : 11
},
{
"routeIdxFrom" : 7,
"type" : "A",
"key" : "AA",
"priority" : 100,
"value" : "Endast 2 klass",
"routeIdxTo" : 11
},
{
"routeIdxFrom" : 7,
"type" : "A",
"key" : "AE",
"priority" : 100,
"value" : "Ej reservering",
"routeIdxTo" : 11
}
]
},
"idx" : "0",
"reachable" : true,
"Origin" : {
"time" : "06:31:00",
"id" : "740000003",
"extId" : "740000003",
"type" : "ST",
"lat" : 55.609456000000002,
"lon" : 13.000909999999999,
"routeIdx" : 7,
"name" : "Malmö Centralstation",
"date" : "2019-06-23"
},
"Destination" : {
"time" : "06:58:00",
"id" : "740000260",
"extId" : "740000260",
"type" : "ST",
"lat" : 55.837719,
"lon" : 13.305491,
"routeIdx" : 11,
"name" : "Eslöv station",
"date" : "2019-06-23"
},
"direction" : "Kristianstad Centralstation",
"Stops" : {
"Stop" : [
{
"id" : "740000003",
"extId" : "740000003",
"lat" : 55.609456000000002,
"lon" : 13.000909999999999,
"routeIdx" : 7,
"depTime" : "06:31:00",
"name" : "Malmö Centralstation",
"depDate" : "2019-06-23"
},
{
"id" : "740000120",
"extId" : "740000120",
"lat" : 55.708094000000003,
"lon" : 13.186897,
"arrTime" : "06:42:00",
"arrDate" : "2019-06-23",
"routeIdx" : 8,
"depTime" : "06:44:00",
"name" : "Lund Centralstation",
"depDate" : "2019-06-23"
},
{
"id" : "740000834",
"extId" : "740000834",
"lat" : 55.751153000000002,
"lon" : 13.200201,
"arrTime" : "06:49:00",
"arrDate" : "2019-06-23",
"routeIdx" : 9,
"depTime" : "06:49:00",
"name" : "Stångby station (Lund kn)",
"depDate" : "2019-06-23"
},
{
"id" : "740000961",
"extId" : "740000961",
"lat" : 55.778928999999998,
"lon" : 13.243969,
"arrTime" : "06:53:00",
"arrDate" : "2019-06-23",
"routeIdx" : 10,
"depTime" : "06:53:00",
"name" : "Örtofta station (Eslöv kn)",
"depDate" : "2019-06-23"
},
{
"id" : "740000260",
"extId" : "740000260",
"lat" : 55.837719,
"lon" : 13.305491,
"arrTime" : "06:58:00",
"arrDate" : "2019-06-23",
"routeIdx" : 11,
"name" : "Eslöv station"
}
]
},
"name" : "Länstrafik - Tåg 1405",
"transportNumber" : "1405"
}
]
},
"ServiceDays" : [
{
"sDaysB" : "FFFFFFFFFFFFFFFC",
"sDaysR" : "daily",
"planningPeriodBegin" : "2019-06-18",
"planningPeriodEnd" : "2019-08-18"
}
],
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230631$201906230658$JLT 1405$$1$",
"tripId" : "C-2",
"duration" : "PT27M"
},
{
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230723$201906230747$JLT 1514$$1$",
"LegList" : {
"Leg" : [
{
"transportCategory" : "JLT",
"type" : "JNY",
"name" : "Länstrafik - Tåg 1514",
"transportNumber" : "1514",
"Destination" : {
"routeIdx" : 11,
"id" : "740000260",
"name" : "Eslöv station",
"lon" : 13.305491,
"extId" : "740000260",
"date" : "2019-06-23",
"time" : "07:47:00",
"type" : "ST",
"lat" : 55.837719
},
"direction" : "Helsingborg Centralstation",
"idx" : "0",
"reachable" : true,
"Notes" : {
"Note" : [
{
"priority" : 100,
"key" : "VG",
"type" : "A",
"value" : "Pågatågen",
"routeIdxTo" : 11,
"routeIdxFrom" : 8
},
{
"priority" : 100,
"key" : "AA",
"type" : "A",
"value" : "Endast 2 klass",
"routeIdxTo" : 11,
"routeIdxFrom" : 8
},
{
"priority" : 100,
"key" : "AE",
"type" : "A",
"value" : "Ej reservering",
"routeIdxTo" : 11,
"routeIdxFrom" : 8
}
]
},
"Stops" : {
"Stop" : [
{
"depTime" : "07:23:00",
"name" : "Malmö Centralstation",
"id" : "740000003",
"routeIdx" : 8,
"extId" : "740000003",
"lat" : 55.609456000000002,
"lon" : 13.000909999999999,
"depDate" : "2019-06-23"
},
{
"arrDate" : "2019-06-23",
"depDate" : "2019-06-23",
"name" : "Hjärup station (Staffanstorp kn)",
"id" : "740000942",
"routeIdx" : 9,
"extId" : "740000942",
"arrTime" : "07:30:00",
"lat" : 55.674151000000002,
"lon" : 13.136512,
"depTime" : "07:30:00"
},
{
"arrDate" : "2019-06-23",
"depDate" : "2019-06-23",
"name" : "Lund Centralstation",
"id" : "740000120",
"routeIdx" : 10,
"extId" : "740000120",
"arrTime" : "07:35:00",
"lat" : 55.708094000000003,
"lon" : 13.186897,
"depTime" : "07:37:00"
},
{
"name" : "Eslöv station",
"id" : "740000260",
"routeIdx" : 11,
"extId" : "740000260",
"arrTime" : "07:47:00",
"lat" : 55.837719,
"lon" : 13.305491,
"arrDate" : "2019-06-23"
}
]
},
"Product" : {
"name" : "Länstrafik - Tåg 1514",
"catOutS" : "JLT",
"catOutL" : "Länstrafik - Tåg",
"operatorCode" : "276",
"catCode" : "4",
"operator" : "Skånetrafiken",
"operatorUrl" : "http:\/\/www.skanetrafiken.se",
"num" : "1514"
},
"Origin" : {
"name" : "Malmö Centralstation",
"id" : "740000003",
"time" : "07:23:00",
"extId" : "740000003",
"routeIdx" : 8,
"lat" : 55.609456000000002,
"date" : "2019-06-23",
"lon" : 13.000909999999999,
"type" : "ST"
}
}
]
},
"tripId" : "C-3",
"duration" : "PT24M",
"idx" : 3,
"ServiceDays" : [
{
"sDaysB" : "FFFFFFFFFFFFFFFC",
"planningPeriodBegin" : "2019-06-18",
"planningPeriodEnd" : "2019-08-18",
"sDaysR" : "daily"
}
]
},
{
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230731$201906230758$JLT 1407$$1$",
"LegList" : {
"Leg" : [
{
"Product" : {
"name" : "Länstrafik - Tåg 1407",
"catCode" : "4",
"operator" : "Skånetrafiken",
"catOutL" : "Länstrafik - Tåg",
"catOutS" : "JLT",
"operatorUrl" : "http:\/\/www.skanetrafiken.se",
"num" : "1407",
"operatorCode" : "276"
},
"idx" : "0",
"Notes" : {
"Note" : [
{
"value" : "Pågatågen",
"type" : "A",
"routeIdxFrom" : 7,
"routeIdxTo" : 11,
"key" : "VG",
"priority" : 100
},
{
"value" : "Endast 2 klass",
"type" : "A",
"routeIdxFrom" : 7,
"routeIdxTo" : 11,
"key" : "AA",
"priority" : 100
},
{
"value" : "Ej reservering",
"type" : "A",
"routeIdxFrom" : 7,
"routeIdxTo" : 11,
"key" : "AE",
"priority" : 100
}
]
},
"transportNumber" : "1407",
"type" : "JNY",
"transportCategory" : "JLT",
"Stops" : {
"Stop" : [
{
"depTime" : "07:31:00",
"depDate" : "2019-06-23",
"extId" : "740000003",
"lon" : 13.000909999999999,
"lat" : 55.609456000000002,
"id" : "740000003",
"name" : "Malmö Centralstation",
"routeIdx" : 7
},
{
"depTime" : "07:44:00",
"depDate" : "2019-06-23",
"extId" : "740000120",
"lon" : 13.186897,
"arrDate" : "2019-06-23",
"arrTime" : "07:42:00",
"lat" : 55.708094000000003,
"id" : "740000120",
"name" : "Lund Centralstation",
"routeIdx" : 8
},
{
"depTime" : "07:49:00",
"depDate" : "2019-06-23",
"extId" : "740000834",
"lon" : 13.200201,
"arrDate" : "2019-06-23",
"arrTime" : "07:49:00",
"lat" : 55.751153000000002,
"id" : "740000834",
"name" : "Stångby station (Lund kn)",
"routeIdx" : 9
},
{
"depTime" : "07:53:00",
"depDate" : "2019-06-23",
"extId" : "740000961",
"lon" : 13.243969,
"arrDate" : "2019-06-23",
"arrTime" : "07:53:00",
"lat" : 55.778928999999998,
"id" : "740000961",
"name" : "Örtofta station (Eslöv kn)",
"routeIdx" : 10
},
{
"lon" : 13.305491,
"extId" : "740000260",
"arrDate" : "2019-06-23",
"arrTime" : "07:58:00",
"lat" : 55.837719,
"id" : "740000260",
"name" : "Eslöv station",
"routeIdx" : 11
}
]
},
"reachable" : true,
"direction" : "Kristianstad Centralstation",
"Destination" : {
"type" : "ST",
"extId" : "740000260",
"lon" : 13.305491,
"date" : "2019-06-23",
"time" : "07:58:00",
"lat" : 55.837719,
"id" : "740000260",
"name" : "Eslöv station",
"routeIdx" : 11
},
"Origin" : {
"type" : "ST",
"extId" : "740000003",
"lon" : 13.000909999999999,
"date" : "2019-06-23",
"time" : "07:31:00",
"lat" : 55.609456000000002,
"id" : "740000003",
"name" : "Malmö Centralstation",
"routeIdx" : 7
},
"name" : "Länstrafik - Tåg 1407"
}
]
},
"tripId" : "C-4",
"duration" : "PT27M",
"idx" : 4,
"ServiceDays" : [
{
"planningPeriodBegin" : "2019-06-18",
"sDaysR" : "daily",
"sDaysB" : "FFFFFFFFFFFFFFFC",
"planningPeriodEnd" : "2019-08-18"
}
]
},
{
"ctxRecon" : "T$A=1@O=Malmö Centralstation@L=740000003@a=128@$A=1@O=Eslöv station@L=740000260@a=128@$201906230823$201906230847$JLT 1518$$1$",
"LegList" : {
"Leg" : [
{
"type" : "JNY",
"name" : "Länstrafik - Tåg 1518",
"Notes" : {
"Note" : [
{
"value" : "Pågatågen",
"routeIdxFrom" : 8,
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"key" : "VG"
},
{
"value" : "Endast 2 klass",
"routeIdxFrom" : 8,
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"key" : "AA"
},
{
"value" : "Ej reservering",
"routeIdxFrom" : 8,
"priority" : 100,
"type" : "A",
"routeIdxTo" : 11,
"key" : "AE"
}
]
},
"Product" : {
"operatorCode" : "276",
"name" : "Länstrafik - Tåg 1518",
"num" : "1518",
"operator" : "Skånetrafiken",
"catOutS" : "JLT",
"catCode" : "4",
"catOutL" : "Länstrafik - Tåg",
"operatorUrl" : "http:\/\/www.skanetrafiken.se"
},
"transportNumber" : "1518",
"direction" : "Helsingborg Centralstation",
"reachable" : true,
"Destination" : {
"routeIdx" : 11,
"type" : "ST",
"name" : "Eslöv station",
"lon" : 13.305491,
"id" : "740000260",
"extId" : "740000260",
"lat" : 55.837719,
"time" : "08:47:00",
"date" : "2019-06-23"
},
"transportCategory" : "JLT",
"Origin" : {
"routeIdx" : 8,
"type" : "ST",
"name" : "Malmö Centralstation",
"lon" : 13.000909999999999,
"id" : "740000003",
"extId" : "740000003",
"lat" : 55.609456000000002,
"time" : "08:23:00",
"date" : "2019-06-23"
},
"idx" : "0",
"Stops" : {
"Stop" : [
{
"routeIdx" : 8,
"depDate" : "2019-06-23",
"name" : "Malmö Centralstation",
"lon" : 13.000909999999999,
"id" : "740000003",
"extId" : "740000003",
"depTime" : "08:23:00",
"lat" : 55.609456000000002
},
{
"routeIdx" : 9,
"depDate" : "2019-06-23",
"arrDate" : "2019-06-23",
"lon" : 13.136512,
"id" : "740000942",
"name" : "Hjärup station (Staffanstorp kn)",
"arrTime" : "08:30:00",
"extId" : "740000942",
"depTime" : "08:30:00",
"lat" : 55.674151000000002
},
{
"routeIdx" : 10,
"depDate" : "2019-06-23",
"arrDate" : "2019-06-23",
"lon" : 13.186897,
"id" : "740000120",
"name" : "Lund Centralstation",
"arrTime" : "08:35:00",
"extId" : "740000120",
"depTime" : "08:37:00",
"lat" : 55.708094000000003
},
{
"routeIdx" : 11,
"name" : "Eslöv station",
"arrDate" : "2019-06-23",
"lon" : 13.305491,
"id" : "740000260",
"arrTime" : "08:47:00",
"extId" : "740000260",
"lat" : 55.837719
}
]
}
}
]
},
"tripId" : "C-5",
"duration" : "PT24M",
"idx" : 5,
"ServiceDays" : [
{
"planningPeriodBegin" : "2019-06-18",
"sDaysR" : "daily",
"planningPeriodEnd" : "2019-08-18",
"sDaysB" : "FFFFFFFFFFFFFFFC"
}
]
}
]
}