json helper error: encode() on a non-object
PermalinkI am trying to use json helper to encode one array:
$json = Loader::helper("json"); $j=0; foreach ($pages as $i ){ $result[$j]['ID'] = $i->getCollectionID(); $result[$j]['title'] = $i->getCollectionName(); $result[$j]['desc']= $i->getCollectionDescription(); $result[$j]['date'] = $i->getCollectionDatePublic('d/m/Y'); $j++; }
When I try
echo $json->encode($result)
When trying to use PHP's json_encode, I get result but my special characters form croatian language are getting escaped with unicode numbers.
My concrete is upgraded from 5.4 to 5.6, and server is CentOS with PHP 5.3 version. I cannot use PHP json_encode with JSON_UNESCAPE as this version doesn't suport it and also, I would rather like to stick with concrete's helpers.
My database is UTF8 formated (that is what mb_detect_encoding is reporting )
I tried to copy files from 5.6.3.2 to my updates/5.6.3.1 directory.
Also, I tried to copy them into main directory as an override, but no luck
I was copying:
concrete/core/helpers/json.php
concrete/helpers/json.php
concrete/libraries/3rdparty/JSON
am I missing something ?
Finaly I upgraded manually to 5.6.3.2 but I still get same error. Any ideas ?
The other thing you could try is html escaping the text before adding it to $info, so any special characters are already taken care of before converting to json.
Tried fresh install with 5.6.3.2 and still same C5 json error: "...on a non-object"
I might pull off with PHP default routine if my custom ( croatian ) characters are not escaped. I don't know if it might be some database thing ? I set collation utf8_unicode_ci and other test was utf8_general_ci but same issue.
Is there some specific thing in the way C5 writes extended characters to database maybe ?
As an experiment, you could try various escaping of the strings before encoding. The risk is that something could get double-escaped and lead to problems in the javascript.
That way, you would still be using the core and would keep future update compatibility through to 5.6.3.2.