ciao!
avrei la necessità di convertire JSON in XML.
questo un esempio del JSON che mia arriva:
codice:
[
{"id":"1","titolo":"TITOLO1","gruppo":"GRUPPO1","testo":"TESTO1"},
{"id":"2","titolo":"TITOLO2","gruppo":"GRUPPO2","testo":"TESTO2"}
]
questa la funzione che sto cercando di usare per la conversione:
Codice PHP:
$array = json_decode('STRINGA JSON', TRUE);
$xml = arrayToXml($array, FALSE);
print_r($xml);
function arrayToXML($array, $xml = FALSE) {
if ($xml === false) {
$xml = new SimpleXMLElement('<root/>');
}
foreach ($array as $key => $value) {
if (is_array($value)) {
arrayToXml($value, $xml->addChild($key));
} else {
$xml->addChild($key, $value);
}
}
return $xml->asXML();
}
questo l'output che ottengo:
codice:
<0>1TITOLO1GRUPPO1TESTO1
<1>2TITOLO2GRUPPO2TESTO2
qualche idea???