I need to send associative array in response. Keys can be dynamic like
{
'a':'1',
'b':'2'
}
I already tried mixed[], mixed, string, string[], array and array[]
. But I always get following result.
{
'1',
'2'
}
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI need to send associative array in response. Keys can be dynamic like
{
'a':'1',
'b':'2'
}
I already tried mixed[], mixed, string, string[], array and array[]
. But I always get following result.
{
'1',
'2'
}
First create this interface in your app/code/Vendor/Module/Api/Data
/**
* Interface which represents associative array item.
*/
interface AssociativeArrayItemInterface
{
/**
* Get key
*
* @return string
*/
public function getKey();
/**
* Get value
*
* @return string
*/
public function getValue();
}
Apply @return \Vendor\Module\Api\Data\AssociativeArrayItemInterface[] datatype for on comment
/**
* @return \Vendor\Module\Api\Data\AssociativeArrayItemInterface[]
**/
public function getSettings();
/**
* @return \Vendor\Module\Api\Data\AssociativeArrayItemInterface[]
**/
public function getExtra();
SECOND OPTION: send data in below formate
[{"a":"1","b":"2"}]