php中的json数据解析有关问题

WBOY
Release: 2016-06-13 12:17:57
Original
809 people have browsed it

php中的json数据解析问题
$arr1=array(
'4'=>array('g'=>'test','b'=>'ssss'),
'2'=>array('g'=>'adaf','b'=>'sfdsf'),
'8'=>array('g'=>'afasf','b'=>'grge'),
);
$arr2=array(
'4'=>array('g'=>'test','b'=>'ssss'),
'2'=>array('g'=>'adaf','b'=>'sfdsf'),
'8'=>array('g'=>'afasf','b'=>'grge'),
);

$jsonencode1=json_encode($arr1);
$jsonencode2=json_encode($arr2);

$json=$jsonencode1.$jsonencode2;
echo $json;
上面是我自己写的测试代码,问题是json编码后的数据被连接在一起了,然后怎么解析数据并且将他输出。
------解决思路----------------------

$arr1 = array(<br />  '4'=>array('g'=>'test','b'=>'ssss'),<br />  '2'=>array('g'=>'adaf','b'=>'sfdsf'),<br />  '8'=>array('g'=>'afasf','b'=>'grge'),<br />);<br />$arr2 = array(<br />  '4'=>array('g'=>'test','b'=>'ssss'),<br />  '2'=>array('g'=>'adaf','b'=>'sfdsf'),<br />  '8'=>array('g'=>'afasf','b'=>'grge'),<br />);<br />$jsonencode  = json_encode(array($arr1, $arr2));<br />echo $jsonencode;
Copy after login
[{"4":{"g":"test","b":"ssss"},"2":{"g":"adaf","b":"sfdsf"},"8":{"g":"afasf","b":"grge"}},{"4":{"g":"test","b":"ssss"},"2":{"g":"adaf","b":"sfdsf"},"8":{"g":"afasf","b":"grge"}}]<br />
Copy after login
如果你是 php5.4 及以上,可以这样美化
$jsonencode  = json_encode(array($arr1, $arr2), JSON_PRETTY_PRINT);<br />echo $jsonencode;
Copy after login
[<br />    {<br />        "4": {<br />            "g": "test",<br />            "b": "ssss"<br />        },<br />        "2": {<br />            "g": "adaf",<br />            "b": "sfdsf"<br />        },<br />        "8": {<br />            "g": "afasf",<br />            "b": "grge"<br />        }<br />    },<br />    {<br />        "4": {<br />            "g": "test",<br />            "b": "ssss"<br />        },<br />        "2": {<br />            "g": "adaf",<br />            "b": "sfdsf"<br />        },<br />        "8": {<br />            "g": "afasf",<br />            "b": "grge"<br />        }<br />    }<br />]<br />
Copy after login

否则请至 fdipzone 的博客看代码实现

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!