2014-04-30 99 views
0
return=array(1) { 
    ["return"]=> 
    string(142) "{"products":[{"pid":"1","name":"gallexy","price":"200.00","created_at":"2014-04-28 11:56:58","updated_at":"0000-00-00 00:00:00"}],"success":1}" 
} 

上面的結果來自服務器我試圖解碼使用但解碼方法,但一次又一次失敗。解碼json編碼值

+1

'$ jsonArr = json_decode($ yourArray ['返回的PHP表示'],TRUE);' –

+0

@AmalMurali它給了我這個結果數組(2){[「products」] => array(1){[0] => array(5){[「pid」] => string(1)「1」[「name」] => string(7)「gallexy」[「price」] => string(6)「200.00」[「created_at」] => string(19)「2014-04 -28 11:56:58「[」updated_at「] => string(19)」0000-00-00 00:00:00「}} [」success「] => int(1)} –

+0

acutlly我希望它採用適當的格式,如pid | 1,像這樣的名字| gallexy –

回答

0

嘗試json_decode($return['return'], TRUE);

0

嘗試添加參數true作爲「json_decode」功能的第二個參數。

json_decode($json,true); e.g

0

使用json_decode,以字符串作爲第一個參數。在第二paramenter把真使得返回PHP數組(多維如果需要的話),如果沒有這個參數將是一個JSON對象

$json_decoded = json_decode($return['return'], true); 

//now you can use the array 

myCoolFunction($json_decoded['products']); 

myCoolFunction($json_decoded['products']['pid']);