json - cakephp updated data with escaping quotes -
by using cakephp framework, have usual array structure follows;
$myusualarray = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); when serialized using json_encode built in php function , update corresponding field using savefield function when check db, values follows;
value in db; "{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5}" during field update read id of current table , apply savefield function.
using: cakephp 2.x
any suggestions?
the problem slashes in json. way handle using beforesave , afterfind callback methods in model encoding / decoding.
in beforesave json_encode($array). in afterfind preg_replace() clean slashes , json_decode(). handled cleanly in model , never have worry anywhere else.
Comments
Post a Comment