Mit Javascript eine API-Liste abfragen

Elite12334

New member
Moin. Ich würde gerne aus folgender Liste, die über einen API-Link+ Key erreichbar ist bestimmte Werte abfragen.
Code:
{
  "result": [
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 33333,
          "Spedition": {
            "ID": 33333,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561197988698655
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 3843706
      },
      {
        "Key": 23,
        "Value": 2273589
      },
      {
        "Key": 24,
        "Value": 1290.0
      },
      {
        "Key": 25,
        "Value": 802.6411743164062
      },
      {
        "Key": 26,
        "Value": 84.9192886352539
      },
      {
        "Key": 27,
        "Value": 90
      },
      {
        "Key": 28,
        "Value": 85
      },
      {
        "Key": 29,
        "Value": ""
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:25:06"
      },
      {
        "Key": 31,
        "Value": 0.016007278580218554
      },
      {
        "Key": 32,
        "Value": 0.037517767399549484
      },
      {
        "Key": 33,
        "Value": 0.0003131647245027125
      },
      {
        "Key": 34,
        "Value": "Scania"
      },
      {
        "Key": 35,
        "Value": "S"
      },
      {
        "Key": 36,
        "Value": 105105.9895324707
      },
      {
        "Key": 37,
        "Value": -16070.081512451172
      },
      {
        "Key": 38,
        "Value": "Воронеж (ITCC)"
      },
      {
        "Key": 41,
        "Value": "18,8 t"
      },
      {
        "Key": 42,
        "Value": "Reifen"
      },
      {
        "Key": 43,
        "Value": "Batman"
      },
      {
        "Key": 44,
        "Value": "Lahti"
      },
      {
        "Key": 45,
        "Value": "DPD"
      },
      {
        "Key": 46,
        "Value": "Kuehne + Nagel"
      },
      {
        "Key": 47,
        "Value": "PM+BtBS+TM"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ],
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 22222,
          "Spedition": {
            "ID": 22222,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561198201045753
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 620340
      },
      {
        "Key": 23,
        "Value": 144528
      },
      {
        "Key": 24,
        "Value": 1400.0
      },
      {
        "Key": 25,
        "Value": 1352.73583984375
      },
      {
        "Key": 26,
        "Value": 83.64701843261719
      },
      {
        "Key": 27,
        "Value": 90
      },
      {
        "Key": 28,
        "Value": 0
      },
      {
        "Key": 29,
        "Value": "EU SIM 1"
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:23:42"
      },
      {
        "Key": 31,
        "Value": 0.0007713276354479603
      },
      {
        "Key": 32,
        "Value": 0.018833141773939133
      },
      {
        "Key": 33,
        "Value": 0.0007801514002494514
      },
      {
        "Key": 34,
        "Value": "Scania"
      },
      {
        "Key": 35,
        "Value": "Streamline"
      },
      {
        "Key": 36,
        "Value": -22189.60382080078
      },
      {
        "Key": 37,
        "Value": -2562.2036638259888
      },
      {
        "Key": 38,
        "Value": "Brussel (TransiNet)"
      },
      {
        "Key": 41,
        "Value": "16,9 t"
      },
      {
        "Key": 42,
        "Value": "Borsäure"
      },
      {
        "Key": 43,
        "Value": "Rotterdam"
      },
      {
        "Key": 44,
        "Value": "Southampton"
      },
      {
        "Key": 45,
        "Value": "WGCC"
      },
      {
        "Key": 46,
        "Value": "TransiNet"
      },
      {
        "Key": 47,
        "Value": "ETS2"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ],
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 22222,
          "Spedition": {
            "ID": 11111,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561198121892290
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 595676
      },
      {
        "Key": 23,
        "Value": 160854
      },
      {
        "Key": 24,
        "Value": 800.0
      },
      {
        "Key": 25,
        "Value": 745.356201171875
      },
      {
        "Key": 26,
        "Value": 64.45394897460938
      },
      {
        "Key": 27,
        "Value": 60
      },
      {
        "Key": 28,
        "Value": 64
      },
      {
        "Key": 29,
        "Value": "EU SIM 1"
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:18:32"
      },
      {
        "Key": 31,
        "Value": 0.08671533316373825
      },
      {
        "Key": 32,
        "Value": 0.022410443052649498
      },
      {
        "Key": 33,
        "Value": 0.005497496575117111
      },
      {
        "Key": 34,
        "Value": "Volvo"
      },
      {
        "Key": 35,
        "Value": "FH Classic"
      },
      {
        "Key": 36,
        "Value": -23666.839584350586
      },
      {
        "Key": 37,
        "Value": -3409.6386108398438
      },
      {
        "Key": 38,
        "Value": "Brussel (EuroAcres)"
      },
      {
        "Key": 41,
        "Value": "12,4 t"
      },
      {
        "Key": 42,
        "Value": "Druckbehälter"
      },
      {
        "Key": 43,
        "Value": "Rotterdam"
      },
      {
        "Key": 44,
        "Value": "Southampton"
      },
      {
        "Key": 45,
        "Value": "WGCC"
      },
      {
        "Key": 46,
        "Value": "TransiNet"
      },
      {
        "Key": 47,
        "Value": "ETS2"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ]
  ],
  "error": false,
  "msg": null,
  "version": 202005061
}

Wie ich allgemein in die Liste reinkomme weiß ich, allerdings fehlt mir das wissen um eine for schleife darauf anzusetzten jeweils z.B. den Usernamen und die ID abzufragen. Könnt ihr mir da helfen?
 
Zuletzt bearbeitet von einem Moderator:
Hier mal ein lauffähiges Beispiel, das es etwas erläutert:
HTML:
<!DOCTYPE html>
<html>
	<head>
		<title>Test</title>
		<meta charset="utf-8">
	</head>
	<body>

<div id="ziel"></div>

<script>
var ergebnis = {
  "result": [
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 33333,
          "Spedition": {
            "ID": 33333,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561197988698655
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 3843706
      },
      {
        "Key": 23,
        "Value": 2273589
      },
      {
        "Key": 24,
        "Value": 1290.0
      },
      {
        "Key": 25,
        "Value": 802.6411743164062
      },
      {
        "Key": 26,
        "Value": 84.9192886352539
      },
      {
        "Key": 27,
        "Value": 90
      },
      {
        "Key": 28,
        "Value": 85
      },
      {
        "Key": 29,
        "Value": ""
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:25:06"
      },
      {
        "Key": 31,
        "Value": 0.016007278580218554
      },
      {
        "Key": 32,
        "Value": 0.037517767399549484
      },
      {
        "Key": 33,
        "Value": 0.0003131647245027125
      },
      {
        "Key": 34,
        "Value": "Scania"
      },
      {
        "Key": 35,
        "Value": "S"
      },
      {
        "Key": 36,
        "Value": 105105.9895324707
      },
      {
        "Key": 37,
        "Value": -16070.081512451172
      },
      {
        "Key": 38,
        "Value": "Воронеж (ITCC)"
      },
      {
        "Key": 41,
        "Value": "18,8 t"
      },
      {
        "Key": 42,
        "Value": "Reifen"
      },
      {
        "Key": 43,
        "Value": "Batman"
      },
      {
        "Key": 44,
        "Value": "Lahti"
      },
      {
        "Key": 45,
        "Value": "DPD"
      },
      {
        "Key": 46,
        "Value": "Kuehne + Nagel"
      },
      {
        "Key": 47,
        "Value": "PM+BtBS+TM"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ],
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 22222,
          "Spedition": {
            "ID": 22222,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561198201045753
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 620340
      },
      {
        "Key": 23,
        "Value": 144528
      },
      {
        "Key": 24,
        "Value": 1400.0
      },
      {
        "Key": 25,
        "Value": 1352.73583984375
      },
      {
        "Key": 26,
        "Value": 83.64701843261719
      },
      {
        "Key": 27,
        "Value": 90
      },
      {
        "Key": 28,
        "Value": 0
      },
      {
        "Key": 29,
        "Value": "EU SIM 1"
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:23:42"
      },
      {
        "Key": 31,
        "Value": 0.0007713276354479603
      },
      {
        "Key": 32,
        "Value": 0.018833141773939133
      },
      {
        "Key": 33,
        "Value": 0.0007801514002494514
      },
      {
        "Key": 34,
        "Value": "Scania"
      },
      {
        "Key": 35,
        "Value": "Streamline"
      },
      {
        "Key": 36,
        "Value": -22189.60382080078
      },
      {
        "Key": 37,
        "Value": -2562.2036638259888
      },
      {
        "Key": 38,
        "Value": "Brussel (TransiNet)"
      },
      {
        "Key": 41,
        "Value": "16,9 t"
      },
      {
        "Key": 42,
        "Value": "Borsäure"
      },
      {
        "Key": 43,
        "Value": "Rotterdam"
      },
      {
        "Key": 44,
        "Value": "Southampton"
      },
      {
        "Key": 45,
        "Value": "WGCC"
      },
      {
        "Key": 46,
        "Value": "TransiNet"
      },
      {
        "Key": 47,
        "Value": "ETS2"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ],
    [
      {
        "Key": 10,
        "Value": {
          "UserName": "XY",
          "ID": 22222,
          "Spedition": {
            "ID": 11111,
            "Name": "TDP - Trans.Log.Int.",
            "ShortName": "TDP",
            "IsRealEco": false
          },
          "InSped": true,
          "FormatName": "[TDP] XY"
        }
      },
      {
        "Key": 11,
        "Value": 2
      },
      {
        "Key": 12,
        "Value": 76561198121892290
      },
      {
        "Key": 13,
        "Value": ""
      },
      {
        "Key": 14,
        "Value": ""
      },
      {
        "Key": 15,
        "Value": 0
      },
      {
        "Key": 16,
        "Value": ""
      },
      {
        "Key": 21,
        "Value": 0
      },
      {
        "Key": 22,
        "Value": 595676
      },
      {
        "Key": 23,
        "Value": 160854
      },
      {
        "Key": 24,
        "Value": 800.0
      },
      {
        "Key": 25,
        "Value": 745.356201171875
      },
      {
        "Key": 26,
        "Value": 64.45394897460938
      },
      {
        "Key": 27,
        "Value": 60
      },
      {
        "Key": 28,
        "Value": 64
      },
      {
        "Key": 29,
        "Value": "EU SIM 1"
      },
      {
        "Key": 30,
        "Value": "05.07.2020 14:18:32"
      },
      {
        "Key": 31,
        "Value": 0.08671533316373825
      },
      {
        "Key": 32,
        "Value": 0.022410443052649498
      },
      {
        "Key": 33,
        "Value": 0.005497496575117111
      },
      {
        "Key": 34,
        "Value": "Volvo"
      },
      {
        "Key": 35,
        "Value": "FH Classic"
      },
      {
        "Key": 36,
        "Value": -23666.839584350586
      },
      {
        "Key": 37,
        "Value": -3409.6386108398438
      },
      {
        "Key": 38,
        "Value": "Brussel (EuroAcres)"
      },
      {
        "Key": 41,
        "Value": "12,4 t"
      },
      {
        "Key": 42,
        "Value": "Druckbehälter"
      },
      {
        "Key": 43,
        "Value": "Rotterdam"
      },
      {
        "Key": 44,
        "Value": "Southampton"
      },
      {
        "Key": 45,
        "Value": "WGCC"
      },
      {
        "Key": 46,
        "Value": "TransiNet"
      },
      {
        "Key": 47,
        "Value": "ETS2"
      },
      {
        "Key": 51,
        "Value": ""
      },
      {
        "Key": 52,
        "Value": ""
      },
      {
        "Key": 55,
        "Value": ""
      },
      {
        "Key": 54,
        "Value": ""
      },
      {
        "Key": 53,
        "Value": ""
      },
      {
        "Key": 61,
        "Value": ""
      },
      {
        "Key": 62,
        "Value": 0
      },
      {
        "Key": 63,
        "Value": 0
      },
      {
        "Key": 64,
        "Value": 0
      },
      {
        "Key": 73,
        "Value": ""
      },
      {
        "Key": 72,
        "Value": ""
      },
      {
        "Key": 74,
        "Value": ""
      },
      {
        "Key": 71,
        "Value": ""
      },
      {
        "Key": 75,
        "Value": 0
      },
      {
        "Key": 76,
        "Value": ""
      }
    ]
  ],
  "error": false,
  "msg": null,
  "version": 202005061
};

var zielnode = document.getElementById('ziel');
if (!ergebnis.error) {
	zielnode.innerHTML += 'Kein Fehler, der Spaß beginnt mit Version '
		+ergebnis.version
		+'<br>'
	;
	ergebnis.result.forEach(function(ref){
		zielnode.innerHTML += '<br><b>Neuer Datensatz:</b><br>';
		ref.forEach(function(innerref){
			if (parseInt(innerref.Key,10) == 10) {
				zielnode.innerHTML += '<b>ID und Name: '
					+innerref['Value'].ID
					+' => '
					+innerref['Value'].UserName
					+'</b>'
				;
			}
			else {
				zielnode.innerHTML += 'Schlüssel: "'
					+innerref.Key
					+'" = '
				;
				var art = typeof innerref['Value'];
				if (art == 'string' || art == 'number') {
					zielnode.innerHTML += innerref['Value'];
				}
			}
			zielnode.innerHTML += '<br>';
		});
	});
}
else { alert('Fehler "'+ergebnis.msg+'"!'); }
</script>

	</body>
</html>
Bei Fragen fragen! :icon7:
 
Andere einträge habe ich immer so abgefragt.

HTML:
$(function (){
    var key = "Api-Key";
    var url = "https://api.sped-v.de/rest/api?apikey=" + key + "&function=";
    $.ajax({
        type: "POST",
        url: url + "getmyrank",
        cache: false,
        success: function(data) {
            var spedv_rank = data.result.Name;
            document.getElementById("spedv_rank").innerHTML = spedv_rank;
        }
    });
});


Also um in die Liste zu kommen braucht man in dem oben genannten Fall:

https://api.sped-v.de/rest/api?apikey="Api-Key"&function=getonlineusers

War das gemeint?
 
Zuletzt bearbeitet von einem Moderator:
Okay, danke das werde ich versuchen. Sollte irgendwas nicht klappen oder ich weiter fragen haben melde ich mich. Danke dir!
 
Wir haben das Thema per E-Mail weiter behandelt, weil es keine Testinstanz gibt. Und ich glaube, wir sind schon nah an der Endlösung.
 
Zurück
Oben