-1

我有一个字段格式:

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

如何以格式将数据放入数组中:

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

这个想法如何

4

3 回答 3

3
$data = '{"2G Network":"GSM 850","3G Network":"HSDPA 850"}';

$myArray = json_decode( $data, true ); //true to make it associative array

http://php.net/manual/en/function.json-decode.php

于 2012-06-11T15:50:56.877 回答
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)
}
于 2012-06-11T15:50:46.130 回答
0
$text = '{"2G Network":"GSM 850","3G Network":"HSDPA 850"}';
$myArray = json_decode($text, true);

采用:

echo $myArray['2G Network'];
于 2012-06-11T15:59:31.583 回答