How to fetch data from array?


json string: [{"id":"2","value":"1"},{"id":"1","value":"1"},{"id":"3","value":""},{"id":"4","value":""},{"id":"5","value":""},{"id":"6","value":"<br \/>"},{"id":"7","value":"<br \/>"},{"id":"8","value":"<br \/>"},{"id":"9","value":"<br \/>"},{"id":"10","value":"1"}]

decoded: NULL

The output is displayed like this only in mozilla and chrome as well…


output for $item->extra_fields

string(677) “[{“id”:“2”,“value”:“1”},{“id”:“1”,“value”:“1”},{“id”:“3”,“value”:”“},{“id”:“4”,“value”:”“},{“id”:“5”,“value”:”“},{“id”:“6”,“value”:”<br \/>“},{“id”:“7”,“value”:”<br \/>“},{“id”:“8”,“value”:”<br \/>“},{“id”:“9”,“value”:”<br \/>“},{“id”:“10”,“value”:“1”}]”

Ok, so it’s a string.
Beats me why mozilla and chrome show it like that. And beats me why decode works with a hardcoded string, and not with the same string coming from your $item class.

Yes thats the thing…Static string if given it takes and decodes it and everything works perfectly but it’s not taking properly from item class…

i even tried to type cast it this way (string)$item->extra_fields but still not working…

Also, this is the content of

[{“id”:“2”,“value”:“1”},{“id”:“1”,“value”:“1”},{“id”:“3”,“value”:“”},{“id”:“4”,“value”:“”},{“id”:“5”,“value”:“”},{“id”:“6”,“value”:“<br \/>”},{“id”:“7”,“value”:“<br \/>”},{“id”:“8”,“value”:“<br \/>”},{“id”:“9”,“value”:“<br \/>”},{“id”:“10”,“value”:“1”}]

in the value of id 6,7,8,9 is “<br \/>”… so would that be the cause of problem ??? like when given as static string “<br \/>” changes to blank or is removed ?

Finally, I got it and probably was a stupid mistake and a check i didnt do.

The string that was being fetched from database was showing properly in the brower but when i checked it by viewing the source the string was having “"” instead of double quote…

So I just used below code to replace and there got my problem solved…

Thank You for the time and help…:slight_smile:

Take a look at PHP: html_entity_decode - Manual