Fix JSON encoding to be fully XE-compatible

This commit is contained in:
Kijin Sung 2016-02-26 14:58:42 +09:00
parent 93ca2acdc8
commit 379bed000d
2 changed files with 28 additions and 15 deletions

View file

@ -15,20 +15,37 @@ class JSONDisplayHandler
$variables['error'] = $oModule->getError(); $variables['error'] = $oModule->getError();
$variables['message'] = $oModule->getMessage(); $variables['message'] = $oModule->getMessage();
$temp = array(); self::_convertCompat($variables, Context::getRequestMethod());
foreach ($variables as $key => $value) return json_encode($variables);
}
/**
* Convert arrays in a format that is compatible with XE.
*
* @param array $array
* @param string $compat_type
* @return array
*/
protected static function _convertCompat(&$array, $compat_type = 'JSON')
{
foreach ($array as $key => &$value)
{ {
if (self::_isNumericArray($value)) if (is_array($value))
{ {
$temp[$key] = array_values($value); self::_convertCompat($value, $compat_type);
} if (self::_isNumericArray($value))
else {
{ if ($compat_type === 'XMLRPC')
$temp[$key] = $value; {
$value = array('item' => array_values($value));
}
else
{
$value = array_values($value);
}
}
} }
} }
return json_encode($temp);
} }
/** /**

View file

@ -69,11 +69,7 @@
var result = {}; var result = {};
$.each(data, function(key, val) { $.each(data, function(key, val) {
if ($.inArray(key, ["error", "message", "act", "redirect_url"]) >= 0 || $.inArray(key, return_fields) >= 0) { if ($.inArray(key, ["error", "message", "act", "redirect_url"]) >= 0 || $.inArray(key, return_fields) >= 0) {
if ($.isArray(val)) { result[key] = val;
result[key] = { item: val };
} else {
result[key] = val;
}
} }
}); });