php 解析json数据,解析失败,求助大神 示例如下:
<?php//第一步,数组源数据$a=['2'=>2,'3'=>3,'4'=>json_encode(['5'=>'5','6'=>'6'])];$b=['a'=>jso...
<?php
//第一步,数组源数据
$a=['2'=>2,'3'=>3,'4'=>json_encode(['5'=>'5','6'=>'6'])];
$b=['a'=>json_encode($a),'b'=>['a'=>'b']];
$json = json_encode($b);
echo $json;
//结果:{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"5\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}
echo "<br/>----------------------------<br/>";
//第二步,解析刚才的数据,也是正确的
$arr=json_decode($json,true);
print_r($arr);
//结果:Array ( [a] => {"2":2,"3":3,"4":"{\"5\":\"5\",\"6\":\"6\"}"} [b] => Array ( [a] => b ) )
echo "<br/>----------------------------<br/>";
//第三步,把输出的json数据拿出来直接解析,不行了,无结果
$json='{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"5\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}';
$arr=json_decode($json,true);
print_r($arr);
请问大神们 怎么样可以第三步的结果和第二步一样?求解
最终要解析的接送是这种格式的,就这段json 解析出来就行
$json='{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"\\\你好,CC\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}';
$arr=json_decode($json,true);
print_r($arr);
请问大神们 怎么样可以第三步的结果和第二步一样?求解提高悬赏了,60分,都给你了,大神快来解答吧:) 展开
//第一步,数组源数据
$a=['2'=>2,'3'=>3,'4'=>json_encode(['5'=>'5','6'=>'6'])];
$b=['a'=>json_encode($a),'b'=>['a'=>'b']];
$json = json_encode($b);
echo $json;
//结果:{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"5\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}
echo "<br/>----------------------------<br/>";
//第二步,解析刚才的数据,也是正确的
$arr=json_decode($json,true);
print_r($arr);
//结果:Array ( [a] => {"2":2,"3":3,"4":"{\"5\":\"5\",\"6\":\"6\"}"} [b] => Array ( [a] => b ) )
echo "<br/>----------------------------<br/>";
//第三步,把输出的json数据拿出来直接解析,不行了,无结果
$json='{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"5\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}';
$arr=json_decode($json,true);
print_r($arr);
请问大神们 怎么样可以第三步的结果和第二步一样?求解
最终要解析的接送是这种格式的,就这段json 解析出来就行
$json='{"a":"{\"2\":2,\"3\":3,\"4\":\"{\\\"5\\\":\\\"\\\你好,CC\\\",\\\"6\\\":\\\"6\\\"}\"}","b":{"a":"b"}}';
$arr=json_decode($json,true);
print_r($arr);
请问大神们 怎么样可以第三步的结果和第二步一样?求解提高悬赏了,60分,都给你了,大神快来解答吧:) 展开
1个回答
展开全部
<?php
define('MY_JSON_SLICE', 1);
define('MY_JSON_IN_STR', 2);
define('MY_JSON_IN_ARR', 3);
define('MY_JSON_IN_OBJ', 4);
define('MY_JSON_IN_CMT', 5);
define('MY_JSON_LOOSE_TYPE', 16);
define('MY_JSON_SUPPRESS_ERRORS', 32);
class MY_JSON
{
function MY_JSON($use = 0)
{
$this->use = $use;
}
function utf162utf8($utf16)
{
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
switch (true) {
case ((0x7F & $bytes) == $bytes):
return chr(0x7F & $bytes);
case (0x07FF & $bytes) == $bytes:
return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F));
case (0xFFFF & $bytes) == $bytes:
return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F));
}
return '';
}
define('MY_JSON_SLICE', 1);
define('MY_JSON_IN_STR', 2);
define('MY_JSON_IN_ARR', 3);
define('MY_JSON_IN_OBJ', 4);
define('MY_JSON_IN_CMT', 5);
define('MY_JSON_LOOSE_TYPE', 16);
define('MY_JSON_SUPPRESS_ERRORS', 32);
class MY_JSON
{
function MY_JSON($use = 0)
{
$this->use = $use;
}
function utf162utf8($utf16)
{
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
switch (true) {
case ((0x7F & $bytes) == $bytes):
return chr(0x7F & $bytes);
case (0x07FF & $bytes) == $bytes:
return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F));
case (0xFFFF & $bytes) == $bytes:
return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F));
}
return '';
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询