Jump to content

brunindf26

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Comum

About brunindf26

  1. brunindf26

    PHP + JSON

    Boa tarde, Eu tenho um arquivo json que está me retornando da seguinte maneira. {"ntg-version":"19.1.30.1719","treesize":3500,"sensors":[{"objid":100044,"downtimesince":"","downtimesince_raw":"","tags":"bandwidthsensor snmptrafficsensor OI MG Central-1003 Rede-Terrestre Rede-Cooperativas","device":"3169-80 | PSA5054927 |"},{"objid":100045,"downtimesince":"","downtimesince_raw":"","tags":"WAN Oi-R1-256Kb OI MG Central-1003 Rede-Terrestre Rede-Cooperativas","device":"3169-31 | PSA5054627 |"},{"objid":100047,"downtimesince":"","downtimesince_raw":"","tags":"WAN Algar-128Kb ALGAR MG Central-1003 Rede-Terrestre Rede-Cooperativas","device":"8178-0 | 0000137653-URA |"},{"objid":100048,"downtimesince":"","downtimesince_raw":"","tags":"bandwidthsensor snmptrafficsensor ALGAR MG Central-1003 Rede-Terrestre Rede-Cooperativas","device":"3178-0 | 0000187583-URA |"},{"objid":10006,"downtimesince":"","downtimesince_raw":"","tags":"bandwidthsensor snmptrafficsensor OI PR Central-2009 Rede-Terrestre Rede-Cooperativas","device":"5340-11 | TAA0738587 | 103.28.31.253"}] Porém necessito separar os valores que estão nos itens device e tags. Isso já estou conseguindo fazer. O problema esta sendo na hora de gerar o novo array que está dando um loop. Saindo o seguinte resultado: Array ( [0] => Array ( [objid] => 100044 [downtimesince] => [Coop] => 2459-31 [Desi] => PSA505125447 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-14553 ) ) Array ( [0] => Array ( [objid] => 100044 [downtimesince] => [Coop] => 24569-31 [Desi] => PSA50545827 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-2115503 ) [1] => Array ( [objid] => 100045 [downtimesince] => [Coop] => 544169-31 [Desi] => PSA50544527 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-1003 ) ) Array ( [0] => Array ( [objid] => 100044 [downtimesince] => [Coop] => 25469-31 [Desi] => PSA5054827 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-2543 ) [1] => Array ( [objid] => 100045 [downtimesince] => [Coop] => 25469-31 [Desi] => PSA50545587 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-4452 ) [2] => Array ( [objid] => 100047 [downtimesince] => [Coop] => 545178-0 [Desi] => 00015453-URA [Ipsat] => [Operadora] => ALGAR [Uf] => MG [Central] => Central-548003 ) ) Array ( [0] => Array ( [objid] => 100044 [downtimesince] => [Coop] => 54169-31 [Desi] => PSA5542827 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-3615 ) [1] => Array ( [objid] => 100045 [downtimesince] => [Coop] => 5869-31 [Desi] => PSA5054451557 [Ipsat] => [Operadora] => OI [Uf] => MG [Central] => Central-254 ) [2] => Array ( [objid] => 100047 [downtimesince] => [Coop] => 55178-0 [Desi] => 000dada663-URA [Ipsat] => [Operadora] => ALGAR [Uf] => MG [Central] => Central-12555 ) [3] => Array ( [objid] => 100048 [downtimesince] => [Coop] => 5178-0 [Desi] => 0000137dada3-URA [Ipsat] => [Operadora] => ALGAR [Uf] => MG [Central] => Central-10255 ) ) segue meu script <?php $url = "http://localhost/json.html"; $info = file_get_contents($url); $data = json_decode($info); $arr = array(); foreach($data->sensors as $item){ $device = utf8_decode($item -> device); $downtimesince = utf8_decode($item -> downtimesince); $tags = ($item -> tags); $objid = utf8_decode($item -> objid); list($coop, $des, $ipsat) = array_pad(explode('|',$device), 3, ''); list($nada1, $nada2, $operadora, $uf, $central) = array_pad(explode(' ',$tags), 5, ''); $arr[] = array( objid => $objid, downtimesince => $downtimesince, Coop => $coop, Desi => $des, Ipsat => $ipsat, Operadora => $operadora, Uf => $uf, Central => $central ); echo ("<pre>"); print_r($arr); echo ("</pre>"); } ?>
×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.