2016-10-27 2 views
-2

У меня есть следующий формат JSON, который я получаю. Я хочу расшифровать это в PHP. Но я не могу найти, как я могу получить данные в ключе DATA в следующем формате.Как декодировать формат JSON с помощью PHP?

JSON:

firedAt => Thu, 05 Feb 2015 20:00:13 GMT 
event => orderPaid 
data => [ 
    { 
    "id": 10263410, 
    "total": 219.00, 
    "shipping": 0.00, 
    "status": { 
     "id": 2578171, 
     "title": "Betalning mottagen", 
     "color": "#c0ffc0", 
     "is_paid": true, 
     "is_delivered": false, 
     "is_active": true 
    }, 
    "note": null, 
    "order_id": 10187, 
    "deleted": false, 
    "updated": null, 
    "created": "2015-02-05 21:33:18", 
    "reminder_sent": false, 
    "market": 10, 
    "market_reference": "47335091", 
    "new": true, 
    "integration": 274029, 
    "weight": "0", 
    "deliver_date": null, 
    "rows": [ 
     { 
     "id": 9086694, 
     "quantity": 1, 
     "title": "Mobilskal 62613-BRU", 
     "reference": "62613-BRU", 
     "price": 219, 
     "market_reference": "26971426", 
     "tax": "25", 
     "created": "2015-02-05 21:33:18", 
     "product_id": null, 
     "integration": 274021, 
     "vat": 43.8 
     } 
    ], 
    "customer": { 
     "contact": { 
     "id": 934714, 
     "alias": "Jane Doe", 
     "email": "[email protected]", 
     "phone": "0812839183", 
     "mobile": "0721231234" 
     }, 
     "address": { 
     "id": 934714, 
     "first_name": "Jane", 
     "last_name": "Doe Svensson", 
     "address": "Kungsgatan 6", 
     "address2": "", 
     "zip": "37450", 
     "city": "Asarum", 
     "country": { 
      "name": "Sverige", 
      "code": "se" 
     } 
     }, 
     "invoice": { 
     "id": 934714, 
     "first_name": "Jane", 
     "last_name": "Doe Svensson", 
     "address": "Kungsgatan 6", 
     "address2": "", 
     "zip": "37450", 
     "city": "Asarum", 
     "country": { 
      "name": "Sverige", 
      "code": "se" 
     } 
     } 
    }, 
    "history": [ 
     { 
     "id": "4457827", 
     "created": "2015-02-05 21:33:18", 
     "message": "Ny orderrad: 1 st Mobilskal 62613-BRU" 
     } 
    ], 
    "icon": [ 
    ] 
    } 
] 
+1

Некоторые это JSON, первый бит не является, так что не будет декодировать. –

+0

Если у вас хороший JSON (нет синтаксических ошибок), вы можете использовать это. json_decode ($ JSON, true); –

+0

Так что нет возможности расшифровать? – eweb

ответ

0
json_decode($JSON['data'], true); 

ИЛИ

$array = json_decode('{ 
"id": 10263410, 
"total": 219.00, 
"shipping": 0.00, 
"status": { 
    "id": 2578171, 
    "title": "Betalning mottagen", 
    "color": "#c0ffc0", 
    "is_paid": true, 
    "is_delivered": false, 
    "is_active": true 
}, 
"note": null, 
"order_id": 10187, 
"deleted": false, 
"updated": null, 
"created": "2015-02-05 21:33:18", 
"reminder_sent": false, 
"market": 10, 
"market_reference": "47335091", 
"new": true, 
"integration": 274029, 
"weight": "0", 
"deliver_date": null, 
"rows": [ 
    { 
    "id": 9086694, 
    "quantity": 1, 
    "title": "Mobilskal 62613-BRU", 
    "reference": "62613-BRU", 
    "price": 219, 
    "market_reference": "26971426", 
    "tax": "25", 
    "created": "2015-02-05 21:33:18", 
    "product_id": null, 
    "integration": 274021, 
    "vat": 43.8 
    } 
], 
"customer": { 
    "contact": { 
    "id": 934714, 
    "alias": "Jane Doe", 
    "email": "[email protected]", 
    "phone": "0812839183", 
    "mobile": "0721231234" 
    }, 
    "address": { 
    "id": 934714, 
    "first_name": "Jane", 
    "last_name": "Doe Svensson", 
    "address": "Kungsgatan 6", 
    "address2": "", 
    "zip": "37450", 
    "city": "Asarum", 
    "country": { 
     "name": "Sverige", 
     "code": "se" 
    } 
    }, 
    "invoice": { 
    "id": 934714, 
    "first_name": "Jane", 
    "last_name": "Doe Svensson", 
    "address": "Kungsgatan 6", 
    "address2": "", 
    "zip": "37450", 
    "city": "Asarum", 
    "country": { 
     "name": "Sverige", 
     "code": "se" 
    } 
    } 
}, 
"history": [ 
    { 
    "id": "4457827", 
    "created": "2015-02-05 21:33:18", 
    "message": "Ny orderrad: 1 st Mobilskal 62613-BRU" 
    } 
], 
"icon": [ 
] 
}', true); 
Смежные вопросы