Я собираюсь создать объект php, чтобы построить свою собственную таблицу из ответа xml api.
Я пытался преобразовать XML-ответ API в Json, но не могу превратить его в объект php. PHP для меня новый ...
class ParserMy {
public static function jsonToDebug($jsonText = '')
{
$arr = json_decode($jsonText, true);
$html = "";
if ($arr && is_array($arr)) {
echo "".json_encode($arr,JSON_PRETTY_PRINT)."
"; // $ html. = Self :: _ arrayToHtmlTableRecursive ($ arr);} return $ html;}} $ url =" .... url ... . "; $ xml = simplexml_load_file ($ url); $ json = json_encode ($ xml); echo ParserMy :: jsonToDebug ($ json);
Я хочу преобразовать ответ json или xml в массив изобъекты, но есть больше атрибутов ... которыми я не могу управлять.
Пример из этого json в:
{
"station": [
{
"@attributes": {
"id": "27",
"co": "SH",
"co_name": "Shell",
"lat": "",
"lng": "",
"name": "Shell - QE",
"address": "",
"street_code": "",
"highway_id": "",
"highway": "",
"zip": "",
"city": "",
"city_name": "",
"provincia": "",
"fuels": "bde",
"phone": "",
"status": "AP",
"neighbour_distance": "",
"insertion_date": "2008-01-01 00:00",
"last_updated": "2013-12-31 00:00",
"latest_price_change": "",
"highres": "0",
"photos": "0",
"tags": "",
"user": "qe"
},
"reports": {
"report": [
{
"@attributes": {
"price": "1.666",
"date": "2018-04-09 00:00:00",
"service": "CS",
"fuel": "diesel"
}
},
{
"@attributes": {
"price": "1.782",
"date": "2018-04-09 00:00:00",
"service": "CS",
"fuel": "benzina"
}
}
]
}
}
]
}
в уникальный псевдоним объекта
id: 27
co: SH
co_name: Shell
name: Shell - QE
address:
street_code:
zip:
city:
city_name:
provincia:
phone:
fuels: bde
tags:
lat:
lng:
insertion_date: 2008-01-01 00:00
last_updated: 2013-12-31 00:00
latest_price_change:
diesel (CS) 1.666 il 2018-04-09 00:00:00 cert:
benzina (CS) 1.782 il 2018-04-09 00:00:00 cert:
Спасибо