Tell the solution how to parse JSON in PHP, which comes across this kind of thing:
{"accDo": "a:2:{s:3:"get";s:1:"1";s:4:"take";s:1:"1";}"}
Standard tools return a syntax error.
Tell the solution how to parse JSON in PHP, which comes across this kind of thing:
{"accDo": "a:2:{s:3:"get";s:1:"1";s:4:"take";s:1:"1";}"}
Standard tools return a syntax error.
@nddd , I guess what the problem is. It was about the following:
$arr = array ( 'accDo' => array ( 'get' => '1', 'take' => '1', ) ); foreach($arr as $k => $v){ $arr[$k] = serialize($v); }
Result:
{"accDo":"a:2:{s:3:\"get\";s:1:\"1\";s:4:\"take\";s:1:\"1\";}"}
Slashes were deleted either before being added to the database, or after the output. Who ever thought of converting with two methods? ..
Update
@nddd , there are more competent people on the regular forum, but for now I can offer this option:
// Исходная строка $wrongStr = '{"accDo":"a:2:{s:3:"get";s:1:"1";s:4:"take";s:1:"1";}"}'; // К сериализованной части применяем addslashes() $normalStr = preg_replace_callback( '/a:\d+:([^}]+)}/', create_function( '$matches', 'return addslashes($matches[0]);' ), $wrongStr ); // декодирование $arr = json_decode($normalStr, 1); print_r( unserialize($arr['accDo']) );
Result
Array ( [get] => 1 [take] => 1 )
But I repeat that it would be good to finalize the regular season.
Source: https://ru.stackoverflow.com/questions/384197/
All Articles