i have built a custom module to get Faqs in a REST API.
but the json format not return as what i need!
Expected Result:
{
{
"faq_id": "1",
"category_id": "1",
"question": "What is Lorem Ipsum?",
"answer": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen boo",
"sort_order": "0",
"status": "1"
},
{
"faq_id": "2",
"category_id": "1",
"question": "Why do we use it?",
"answer": "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters",
"sort_order": "0",
"status": "1"
}
}
Current Result:
[
{
"faq_id": "1",
"category_id": "1",
"question": "What is Lorem Ipsum?",
"answer": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen boo",
"sort_order": "0",
"status": "1"
},
{
"faq_id": "2",
"category_id": "1",
"question": "Why do we use it?",
"answer": "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters",
"sort_order": "0",
"status": "1"
}
]
the issue is in this “[“
my code:
API Model:
/**
* {@inheritdoc}
*/
public function getFaqs()
{
$collections = $this->collectionFactory->create()->addFieldToFilter('status', ['eq' => 1]);;
$result = $collections->toArray();
return $result['items'];
}
interface:
interface Faqsinterface
{
/**
* GET for Post api
* @param mixed
* @return array
*/
public function getFaqs();
}
kindly advise, what should i do to solve it?