2012-06-11 132 views
-1

我有一个字段格式:如何将数据放入数组中?

{"2G Network":"GSM 850","3G Network":"HSDPA 850"} 

如何将数据在阵列中的格式:

array(["2G Network"]=>"GSM 850", ["3G Network"]=>"HSDPA 850"); 

如何这个想法

+3

您正在寻找'json_decode()'。 – flowfree

+2

@bsdnoobz我认为你的意思是'json_decode' –

+0

@AleksG是的,我编辑了我的评论。 – flowfree

回答

0
$text = '{"2G Network":"GSM 850","3G Network":"HSDPA 850"}'; 
$myArray = json_decode($text, true); 

用途:

echo $myArray['2G Network']; 
1

你想用json_decode()

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; 

var_dump(json_decode($json, true)); 

array(5) { 
    ["a"] => int(1) 
    ["b"] => int(2) 
    ["c"] => int(3) 
    ["d"] => int(4) 
    ["e"] => int(5) 
}