Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从API获取信息的问题_Php_Api_Php 7 - Fatal编程技术网

Php 从API获取信息的问题

Php 从API获取信息的问题,php,api,php-7,Php,Api,Php 7,实际上,我正在使用一个API从组织中获得一些结果。 但有件事我不能处理事实上jere是我的密码 $responseTournoi=json\u解码($resp); $natures=$responseTournoi->hits; 这为我提供了我想要的信息,但是在这个信息中,我们有一个叫做“naturesEpreuves”的案例,不可能得到它,当我对它进行var_转储时,它告诉我它是一个数组,所以我尝试了很多方法来得到它,但不确定如何正确地得到它,下面是我尝试过的东西和错误: $natures-

实际上,我正在使用一个API从组织中获得一些结果。 但有件事我不能处理事实上jere是我的密码

$responseTournoi=json\u解码($resp);
$natures=$responseTournoi->hits;
这为我提供了我想要的信息,但是在这个信息中,我们有一个叫做“naturesEpreuves”的案例,不可能得到它,当我对它进行var_转储时,它告诉我它是一个数组,所以我尝试了很多方法来得到它,但不确定如何正确地得到它,下面是我尝试过的东西和错误:

$natures->naturesEpreuves[0]
$natures['naturesEpreuves'][0]
在我的API中,我得到了这些信息:

naturesEpreuves 
0   
code    DM
libelle Double Messieurs
sexe    H
valide  True
下面是API调用:

$url_tournoi = "https://api-dev.fft.fr/fft-qlf/v3/competition/tournois";
$curl_tournoi = curl_init();
$dataJSON = json_encode(array(
    "typePratique" => array("PADEL"),
    "from" => 0,
    "size" => 1,
    "dateDebut" => "2020-09-01T00:00:00.000",
    "dateFin" => "2021-12-31T00:00:00.000",
    "type" => array("P"),
));
curl_setopt_array($curl_tournoi, array(
    CURLOPT_URL => $url_tournoi,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => FALSE,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $dataJSON,
    CURLOPT_HTTPHEADER => array(
        "content-type: application/json",
        "Authorization: Bearer $token",
    ),
));
$resp = curl_exec($curl_tournoi);
$responseTournoi = json_decode($resp);
$natures = $responseTournoi->hits;
这里是var_转储:

array (size=1)
  0 => 
    object(stdClass)[4]
      public 'inscriptionEnLigneEnCours' => boolean false
      public 'avecResultatPublie' => boolean false
      public 'code' => string '202157750513004' (length=15)
      public 'nombreDeCourtExterieur' => int 2
      public 'niveauHierarchique' => string 'C' (length=1)
      public 'millesime' => int 2021
      public 'libelle' => string 'TEST 10/06' (length=10)
      public 'codeComite' => string '5775' (length=4)
      public 'installations' => 
        array (size=0)
          empty
      public 'type' => string 'P' (length=1)
      public 'reductionEpreuveSupplementaireJeune' => int 0
      public 'naturesTerrains' => 
        array (size=0)
          empty
      public 'adresse1Engagement' => string 'Centre National d'Entrainement' (length=30)
      public 'reductionEpreuveSupplementaireAdulte' => int 0
      public 'nomComite' => string 'PARIS' (length=5)
      public 'naturesEpreuves' => 
        array (size=1)
          0 => 
            object(stdClass)[5]
              ...
所以,如果你有什么解决办法,我很乐意讨论!
非常感谢

您应该得到如下字段:

$natures->naturesEpreuves;
它是对象内部的属性

如果不起作用,则检查什么是
$natures

var_dump($natures)
编辑:

基于您的var_dump输出,假设这是
$natures
的输出,您应该尝试执行以下操作:

var_dump($natures[0]->naturesEpreuves);
因为,如您所见,对象位于数组内部:

array (size=1)
  0 => 
    object(stdClass)[4]
...

$natures的var_转储是:

array (size=1)
  0 => 
    object(stdClass)[4]
      public 'inscriptionEnLigneEnCours' => boolean false
      public 'avecResultatPublie' => boolean false
      public 'code' => string '202157750513004' (length=15)
      public 'nombreDeCourtExterieur' => int 2
      public 'niveauHierarchique' => string 'C' (length=1)
      public 'millesime' => int 2021
      public 'libelle' => string 'TEST 10/06' (length=10)
      public 'codeComite' => string '5775' (length=4)
      public 'installations' => 
        array (size=0)
          empty
      public 'type' => string 'P' (length=1)
      public 'reductionEpreuveSupplementaireJeune' => int 0
      public 'naturesTerrains' => 
        array (size=0)
          empty
      public 'adresse1Engagement' => string 'Centre National d'Entrainement' (length=30)
      public 'reductionEpreuveSupplementaireAdulte' => int 0
      public 'nomComite' => string 'PARIS' (length=5)
      public 'naturesEpreuves' => 
        array (size=1)
          0 => 
            object(stdClass)[5]
              ...
      public 'jeune' => boolean false
      public 'courrielEngagement' => string 'abaillif@fft.fr' (length=15)
      public 'nomClub' => string 'CLUB TENNIS ENTREPRISE FFT' (length=26)
      public 'installation' => 
        object(stdClass)[6]
          public 'ville' => string 'PARIS 16' (length=8)
          public 'lng' => float 2.256734
          public 'surfaces' => 
            array (size=0)
              ...
          public 'vestiaires' => boolean true
          public 'telephone' => string '0147434554' (length=10)
          public 'codePostal' => string '75016' (length=5)
          public 'adresse1' => string 'Centre National d'Entrainement' (length=30)
          public 'nom' => string 'Stade Roland Garros' (length=19)
          public 'adresse2' => string '4 place de la Porte Molitor' (length=27)
          public 'lat' => float 48.84574
          public 'clubHouse' => boolean true
      public 'id' => int 82236259
      public 'idsArbitres' => 
        array (size=0)
          empty
      public 'nomLigue' => string 'ILE DE FRANCE' (length=13)
      public 'international' => boolean false
      public 'nombreDeCourtInterieur' => int 2
      public 'inscriptionEnLigne' => boolean false
      public 'corpo' => boolean false
      public 'paiementEnLigne' => boolean false
      public 'reductionAdherentJeune' => int 0
      public 'reductionAdherentAdulte' => int 0
      public 'paiementEnLigneObligatoire' => boolean false
      public 'villeEngagement' => string 'PARIS 16' (length=8)
      public 'nomEngagement' => string 'CLUB TENNIS ENTREPRISE FFT' (length=26)
      public 'codeLigue' => string '57' (length=2)
      public 'modeleDeBalle' => 
        object(stdClass)[7]
          public 'libelle' => string 'Gold' (length=4)
          public 'marqueDeBalle' => 
            object(stdClass)[8]
              ...
          public 'id' => int 2901
          public 'valide' => boolean true
          public 'homologue' => boolean true
      public 'senior' => boolean true
      public 'jugeArbitre' => 
        object(stdClass)[9]
          public 'id' => int 205417
          public 'nom' => string 'HELENON' (length=7)
          public 'prenom' => string 'Luc' (length=3)
      public 'adresse2Engagement' => string '4 place de la Porte Molitor' (length=27)
      public 'telBureauEngagement' => string '0147434554' (length=10)
      public 'veteran' => boolean false
      public 'dateDebut' => string '2020-09-12T00:00:00.000' (length=23)
      public 'poules' => boolean false
      public 'cngt' => boolean false
      public 'dateFin' => string '2020-09-19T00:00:00.000' (length=23)
      public 'borneAnneesNaissance' => 
        object(stdClass)[10]
          public 'min' => int 1916
          public 'max' => int 2010
      public 'dateValidation' => string '2020-06-10T16:25:34.073' (length=23)
      public 'codePostalEngagement' => string '75016' (length=5)
      public 'codeClub' => string '57750513' (length=8)

请提供更多的代码,比如API调用!(当然没有凭证)然后当您尝试将其用作对象,然后用作数组时,您会混淆
$natures
是什么。请给我们一个完整的API返回转储。给我们看一下你的var_dump输出,这样我们就可以确定你是否误判了它……我只是编辑了我的帖子,你说:
,这里的var_dump:
,但是你应该告诉我们我们看到的这个变量是什么!我们猜不到。。。我想它是
$natures
?所以,正如我所说的,当我这样做时:````$natures->naturesEpreuves``我有以下几点:注意:试图获取非object的属性'naturesEpreuves',所以
$natures
不是对象,这就是它所说的。$natures->libelle正在工作,例如,但不适用于naturesEpreuves
array (size=1)
  0 => 
    object(stdClass)[4]
...
array (size=1)
  0 => 
    object(stdClass)[4]
      public 'inscriptionEnLigneEnCours' => boolean false
      public 'avecResultatPublie' => boolean false
      public 'code' => string '202157750513004' (length=15)
      public 'nombreDeCourtExterieur' => int 2
      public 'niveauHierarchique' => string 'C' (length=1)
      public 'millesime' => int 2021
      public 'libelle' => string 'TEST 10/06' (length=10)
      public 'codeComite' => string '5775' (length=4)
      public 'installations' => 
        array (size=0)
          empty
      public 'type' => string 'P' (length=1)
      public 'reductionEpreuveSupplementaireJeune' => int 0
      public 'naturesTerrains' => 
        array (size=0)
          empty
      public 'adresse1Engagement' => string 'Centre National d'Entrainement' (length=30)
      public 'reductionEpreuveSupplementaireAdulte' => int 0
      public 'nomComite' => string 'PARIS' (length=5)
      public 'naturesEpreuves' => 
        array (size=1)
          0 => 
            object(stdClass)[5]
              ...
      public 'jeune' => boolean false
      public 'courrielEngagement' => string 'abaillif@fft.fr' (length=15)
      public 'nomClub' => string 'CLUB TENNIS ENTREPRISE FFT' (length=26)
      public 'installation' => 
        object(stdClass)[6]
          public 'ville' => string 'PARIS 16' (length=8)
          public 'lng' => float 2.256734
          public 'surfaces' => 
            array (size=0)
              ...
          public 'vestiaires' => boolean true
          public 'telephone' => string '0147434554' (length=10)
          public 'codePostal' => string '75016' (length=5)
          public 'adresse1' => string 'Centre National d'Entrainement' (length=30)
          public 'nom' => string 'Stade Roland Garros' (length=19)
          public 'adresse2' => string '4 place de la Porte Molitor' (length=27)
          public 'lat' => float 48.84574
          public 'clubHouse' => boolean true
      public 'id' => int 82236259
      public 'idsArbitres' => 
        array (size=0)
          empty
      public 'nomLigue' => string 'ILE DE FRANCE' (length=13)
      public 'international' => boolean false
      public 'nombreDeCourtInterieur' => int 2
      public 'inscriptionEnLigne' => boolean false
      public 'corpo' => boolean false
      public 'paiementEnLigne' => boolean false
      public 'reductionAdherentJeune' => int 0
      public 'reductionAdherentAdulte' => int 0
      public 'paiementEnLigneObligatoire' => boolean false
      public 'villeEngagement' => string 'PARIS 16' (length=8)
      public 'nomEngagement' => string 'CLUB TENNIS ENTREPRISE FFT' (length=26)
      public 'codeLigue' => string '57' (length=2)
      public 'modeleDeBalle' => 
        object(stdClass)[7]
          public 'libelle' => string 'Gold' (length=4)
          public 'marqueDeBalle' => 
            object(stdClass)[8]
              ...
          public 'id' => int 2901
          public 'valide' => boolean true
          public 'homologue' => boolean true
      public 'senior' => boolean true
      public 'jugeArbitre' => 
        object(stdClass)[9]
          public 'id' => int 205417
          public 'nom' => string 'HELENON' (length=7)
          public 'prenom' => string 'Luc' (length=3)
      public 'adresse2Engagement' => string '4 place de la Porte Molitor' (length=27)
      public 'telBureauEngagement' => string '0147434554' (length=10)
      public 'veteran' => boolean false
      public 'dateDebut' => string '2020-09-12T00:00:00.000' (length=23)
      public 'poules' => boolean false
      public 'cngt' => boolean false
      public 'dateFin' => string '2020-09-19T00:00:00.000' (length=23)
      public 'borneAnneesNaissance' => 
        object(stdClass)[10]
          public 'min' => int 1916
          public 'max' => int 2010
      public 'dateValidation' => string '2020-06-10T16:25:34.073' (length=23)
      public 'codePostalEngagement' => string '75016' (length=5)
      public 'codeClub' => string '57750513' (length=8)