mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-15 00:12:43 +09:00
Merge pull request #314 from kijin/pr/json-encode-compat
XML/JSON 반환 포맷의 XE 호환성 개선
This commit is contained in:
commit
8149ecec36
2 changed files with 30 additions and 13 deletions
|
|
@ -15,20 +15,41 @@ class JSONDisplayHandler
|
|||
$variables['error'] = $oModule->getError();
|
||||
$variables['message'] = $oModule->getMessage();
|
||||
|
||||
$temp = array();
|
||||
foreach ($variables as $key => $value)
|
||||
self::_convertCompat($variables, Context::getRequestMethod());
|
||||
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_object($value))
|
||||
{
|
||||
$temp[$key] = array_values($value);
|
||||
$value = get_object_vars($value);
|
||||
}
|
||||
else
|
||||
if (is_array($value))
|
||||
{
|
||||
$temp[$key] = $value;
|
||||
self::_convertCompat($value, $compat_type);
|
||||
if (self::_isNumericArray($value))
|
||||
{
|
||||
if ($compat_type === 'XMLRPC')
|
||||
{
|
||||
$value = array('item' => array_values($value));
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = array_values($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -69,11 +69,7 @@
|
|||
var result = {};
|
||||
$.each(data, function(key, val) {
|
||||
if ($.inArray(key, ["error", "message", "act", "redirect_url"]) >= 0 || $.inArray(key, return_fields) >= 0) {
|
||||
if ($.isArray(val)) {
|
||||
result[key] = { item: val };
|
||||
} else {
|
||||
result[key] = val;
|
||||
}
|
||||
result[key] = val;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue