2015-04-23 42 views
-4

我有一个SELECT查询:转换阵列,并打印出用PHP

Array ([0] => Array ([id] => 1 [id_user] => 1 [id_category] => 1 [name] => Bambas futbol sala [description] => Bambas de futbol sala marca nike, color rojo y negro. Pie 43. [localization] => Barcelona [min_bid] => 25 [expiration] => 300 [terms] => - [highlights] => 0) [1] => Array ([id] => 2 [id_user] => 1 [id_category] => 6 [name] => Bateria electronica Roland td4 [description] => Vendo bateria electronida roland td4 kv versi�n 2009 por falta de tiempo. [localization] => Madrid [min_bid] => 600 [expiration] => 200 [terms] => - [highlights] => 0)) 

,我想它解析到这样一个JSON(与我在阵列得到了各个领域)

"infos":[ [ { "id_user":"1", "id_category":"1", "name":"Bambas futbol sala", "description":"..." }, { "id_user":"2", "id_category":"3", "name":"Bambas futbol sala", "description":"..." } ] ], 

我该怎么做,并用PHP打印?感谢

+2

你尝试json_encode等json_decode? – Random

+0

我试过,但没有工作.. –

回答

1

使用json_encodejson_decode

+0

是的,我试过,但这是行不通的.. –

+0

我有这个代码,并总是这个回我: \t $ statement-> execute(); \t $ rawdata = array(); // $ creamos un array \t while($ row = $ statement-> fetch(PDO :: FETCH_ASSOC)){ \t $ rawdata [] = $ row; \t \t} \t print_r($ rawdata); \t echo“
json encode below:
”; \t echo json_encode($ rawdata,JSON_FORCE_OBJECT); –