Entity JSON encode and manually decode |
In entity
Code: protected $casts = [ Code: courses = array{"bsc-bio", "bsc-bed", "bca"} Code: "a:3:{i:0;s:7:"bsc-bio";i:1;s:7:"bsc-bed";i:2;s:3:"bca";}" Code: json_decode('a:3:{i:0;s:7:"bsc-bio";i:1;s:7:"bsc-bed";i:2;s:3:"bca";}')
That's not in json format, that's encoded with serialize(). You need to use unserialize() to decode it back to an array.
(04-18-2021, 09:15 AM)includebeer Wrote: That's not in json format, that's encoded with serialize(). You need to use unserialize() to decode it back to an array.Got it! Thanks. The unserialize() worked perfectly. But I am having following code in my Entity... PHP Code: protected $casts = [ ![]()
I don't know, I never used this feature. But 'courses' is cast to 'array', not 'json', maybe that's why it's serialized and not encoded in json?
A PHP json_encode array conversion example
PHP | json_encode() Function What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |