|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Jun 2010
Messaggi: 210
|
Aiuto parsing con php
ciao a tutti!!
![]() devo estrapolare da un file contenente questo: Codice:
{"id":1365028063,"title":"Supervisore ISOLA FV","private":"false","feed":"https://api.xively.com/v2/feeds/1365028063.json","status":"live","updated":"2013-10-20T19:07:06.507129Z","created":"2013-10-20T11:37:44.024745Z","creator":"https://xively.com/users/christian1993","version":"1.0.0","datastreams":[{"id":"StatoImpianto","current_value":"0.00","at":"2013-10-20T19:07:06.193250Z","max_value":"0.0","min_value":"0.0","unit":{"symbol":"1 = FV","label":"1 = FV"}},{"id":"TensioneDiBatteria","current_value":"55.08","at":"2013-10-20T19:07:06.193250Z","max_value":"64.69","min_value":"32.72","unit":{"symbol":"V","label":"Volt"}},{"id":"TensioneFotovoltaico","current_value":"0.26","at":"2013-10-20T19:07:06.193250Z","max_value":"65.33","min_value":"0.0","unit":{"symbol":"V","label":"Volt"}},{"id":"WattCARICHI","current_value":"405.00","at":"2013-10-20T19:07:06.193250Z","max_value":"2136.0","min_value":"28.0","unit":{"symbol":"W","label":"Watts"}},{"id":"WattENEL","current_value":"423.00","at":"2013-10-20T19:07:06.193250Z","max_value":"2020.0","min_value":"-199.0","unit":{"symbol":"W","label":"Watts"}}],"product_id":"_PXz62HJQqShYB-LzGC4","device_serial":"Q6ARV37NY9HN"} ne sto uscendo matto, qualcuno di voi ha una soluzione? grazie |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: May 2008
Messaggi: 429
|
la stringa che hai è nel formato json, cerca con google come manipolare oggetti json con php
|
![]() |
![]() |
![]() |
#3 |
Member
Iscritto dal: Jun 2010
Messaggi: 210
|
ciao, grazie per la risposta..
non è che mi potresti fare un esempio pratico tu? io ho provato in questo modo: Codice:
$string = file_get_contents("myText.txt"); $json_a=json_decode($string,true); echo $json_a['TensioneDiBatteria'][current_value]; grazie |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Feb 2010
Messaggi: 523
|
"TensioneDiBatteria" è il valore della chiave "id", mentre "current_value" è la chiave di "55.08"
fatti un brutale var_dump di $json_a (sarebbe meglio usare un po' di semantica anche nel nominare le variabili) e vedi che struttura hai
__________________
AMD Ryzen 5 3600X, ASUS ROG Crosshair VII hero, MSI GeForce RTX 2060 Super Gaming X 8GB, 16GB Corsair Vengeance LPX, Noctua NH-U12S Chromax Black, Samsung 970 EVO Plus 500GB, Corsair RMx Series RM750x, Corsair obsidian 750D |
![]() |
![]() |
![]() |
#5 |
Member
Iscritto dal: Jun 2010
Messaggi: 210
|
ciao,
ho cercato ma in programmazione sono abbastanza limitato, se mi potresti fornire 2 - 3 righe già pronte te ne sarei grato ![]() grazie |
![]() |
![]() |
![]() |
#6 | |
Senior Member
Iscritto dal: Feb 2010
Messaggi: 523
|
Quote:
e qual è il problema?
__________________
AMD Ryzen 5 3600X, ASUS ROG Crosshair VII hero, MSI GeForce RTX 2060 Super Gaming X 8GB, 16GB Corsair Vengeance LPX, Noctua NH-U12S Chromax Black, Samsung 970 EVO Plus 500GB, Corsair RMx Series RM750x, Corsair obsidian 750D |
|
![]() |
![]() |
![]() |
#7 |
Member
Iscritto dal: Jun 2010
Messaggi: 210
|
ho provato con
Codice:
<?php $json = 'myText.txt'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?> |
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: Feb 2010
Messaggi: 523
|
http://php.net/manual/en/function.json-decode.php
"NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit." valida il json ed eventualmente aumenta la depth
__________________
AMD Ryzen 5 3600X, ASUS ROG Crosshair VII hero, MSI GeForce RTX 2060 Super Gaming X 8GB, 16GB Corsair Vengeance LPX, Noctua NH-U12S Chromax Black, Samsung 970 EVO Plus 500GB, Corsair RMx Series RM750x, Corsair obsidian 750D |
![]() |
![]() |
![]() |
#9 |
Member
Iscritto dal: Jun 2010
Messaggi: 210
|
ehh ti ripeto che sono abbastanza ignorante... per me è arabo quello che hai scritto, se mi scrivi una soluzione già pronta all'uso ti rigrazio
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:11.