2017-06-10 28 views
0

我試圖從使用PHP SDK的parse.com獲得訂單。我有訂單類在解析。而訂購類有物品欄是這樣的:parse.com - 如何使用PHP SDK從parse.com查詢和獲取json數組?

[ 
    [ 
    { 
     "id": "uXtRcVLQ3V", 
     "name": "Coca cola", 
     "price": 4, 
     "thumbnail": "https://parsefiles.back4app.com/taT6ySwwyza3B2MJucucqWz9pMqBZ00Pd7w7hoZf/e8e8d5ee1e5242a1acd759827df41473_pdp-coca-cola-hfcs-2l.png", 
     "category": { 
     "id": "cYqrWcCzkt", 
     "name": "İçecek" 
     }, 
     "offer": true 
    }, 
    1 
    ], 
    [ 
    { 
     "id": "DWzLluzSpb", 
     "name": "Darr", 
     "price": 12, 
     "thumbnail": "https://parsefiles.back4app.com/taT6ySwwyza3B2MJucucqWz9pMqBZ00Pd7w7hoZf/8d7c0eae7c74d269319fed0a4f4e50e7_bilisim-paylasimlari.jpg", 
     "category": { 
     "id": "bGVCMX79Y0", 
     "name": "Deterjan, Temizlik" 
     }, 
     "offer": true 
    }, 
    1 
    ] 
] 

我想和回聲名稱,價格,縮略圖,使用PHP解析SDK在陣列中的每個項目的類別。 我的PHP代碼的開頭是:

$query = new ParseQuery("Order"); 
$results = $query->find(); 

enter image description here

+0

我想爲此舉一個例子。 –

+0

@KrisRoofe我沒有從文件中獲取內容,我查詢並從parse.com獲取它 –

回答

0

我已經解決了問題。我使用嵌套的foreach循環。

$query = new ParseQuery("Order"); 
$results = $query->find(); 
foreach($results as $obj) { 
    $items = $obj->get("items"); 
    foreach($items as $prod) { 
     echo $prod[1] . " x " . $prod[0]["name"] . "<br>"; 
    } 
    echo $obj->get("total"); 
}