2014-02-07 54 views
0

我會嘗試顯示導致我的問題的步驟。 我從下面我的MongoDB數據庫獲得的一份文件:php如何在不解碼的情況下輸出json編碼文檔

$monrow= $collection->findOne(array('_id' => new MongoId($id))); //works fine 

我然後JSON編碼$ monrow如下(我需要使用JSON編碼格式)

$monrow= json_encode($monrow); //works fine 
var_dump($monrow); //works fine 
var_dump($monrow->properties); //does not work where properties is an object. 

現在我的問題是,當我做到上述我沒有看到我的表單的值(只看到json編碼的monrow感謝var_dump)。我不得不json_decode($ monrow)再次查看我的表單,並通過解碼,我得到對象(stdClass)在值的前面(這是不需要的)。

問題是如何直接在我的表單中使用json_encoded格式?或者是否可以忽略var_dump輸出中的對象(stdClass)。

這裏是我的var_dump($ monrow)輸出:

string(1804) "{"_id":{"$id":"52e0f51f64657635f1000000"},"campaign_id":1111111,"description":"test","interface_id":2121212121,"mp_commands":"","name":"full pack","properties":{"graph":{"cells":[{"type":"basic.Rect","position":{"x":220,"y":180},"size":{"width":80,"height":40},"angle":0,"script":"Begin","group":"MP Generic","id":"953fd4dc-6a82-4ee3-b03b-7e3eba4c6f6b","embeds":"","z":0,"attrs":{"rect":{"fill":"#1DCC64","stroke":"#3E7F0C","rx":10,"ry":10,"stroke-width":3},"text":{"text":"Begin","fill":"#000000"}}},{"type":"basic.Rect","position":{"x":220,"y":260},"size":{"width":80,"height":40},"angle":0,"script":"Send","group":"SMS","id":"5a158c43-f22a-4380-952f-173f309adfaf","embeds":"","z":1,"message":"Please call number 23094072304","attrs":{"rect":{"fill":"#FFC9C0","stroke":"#7F3124","stroke-width":3},"text":{"text":"Send","fill":"#000000"}}},{"type":"basic.Rect","position":{"x":220,"y":340},"size":{"width":80,"height":40},"angle":0,"script":"End","group":"MP Generic","id":"827f9533-22d1-4331-b21c-5d12c291631d","embeds":"","z":2,"attrs":{"rect":{"fill":"#FF3329","stroke":"#7F1A15","rx":10,"ry":10,"stroke-width":3},"text":{"text":"End","fill":"#000000"}}},{"type":"link","id":"4fadab02-ef30-4a1b-9581-4bc2f03b11c6","embeds":"","source":{"id":"953fd4dc-6a82-4ee3-b03b-7e3eba4c6f6b"},"target":{"id":"5a158c43-f22a-4380-952f-173f309adfaf"},"z":3,"attrs":{".marker-source":{"d":"M 10 0 L 0 5 L 10 10 z","transform":"scale(0.001)"},".marker-target":{"d":"M 10 0 L 0 5 L 10 10 z"}}},{"type":"link","id":"694d255f-de4e-4a1b-b7e5-9634f6e529bd","embeds":"","source":{"id":"5a158c43-f22a-4380-952f-173f309adfaf"},"target":{"id":"827f9533-22d1-4331-b21c-5d12c291631d"},"z":4,"attrs":{".marker-source":{"d":"M 10 0 L 0 5 L 10 10 z","transform":"scale(0.001)"},".marker-target":{"d":"M 10 0 L 0 5 L 10 10 z"}}}]}}}" 
+0

請顯示'var_dump($ monrow);' –

+0

謝謝。我已經將這個信息添加到了問題 – Kingsley

回答

0

嘗試使用json_decode($ monrow,真)獲得stdClass的對象的數組ASSOC insteed。但是看起來你不應該在從MongoDB中檢索文件後直接調用json_encode

+0

,謝謝Ostrovski。通過這樣做(真)我仍然得到一個頁面沒有形式,但與數組 – Kingsley

+0

儘量避免從mongo加載數據後,任何json_ *函數調用。看起來多餘。 –

相關問題