We're currently having an Android-App access some of the entries of our Craft-based website. We are currently still using a self built API, and for easier creation of new API-Calls we are trying to migrate over to Pixel & Tonic's Element API plugin.
The entries (or the blocks of a Matrix-field of that entry, to be more precise) are accessed like so:
'api/alloverlist' => function() { // GET ALLOVER-CHALLENGES
return [
'elementType' => ElementType::Entry,
'criteria' => [
'section' => 'challenges',
],
'paginate' => false,
'first' => true,
'transformer' => function(EntryModel $entry){
$allOverChallenges = [];
foreach ($entry->allOverChallenge as $challenge){
$allOverChallenges[] = [
'elementId' => $challenge->id,
'field_allOverChallenge_allOverName' => $challenge->allOverName,
];
}
return [
$allOverChallenges
];
},
];
},
The returned JSON-String has the following appearance:
[
[
{
"elementId": "1298",
"field_allOverChallenge_allOverName": "Dein schönster Sonnenaufgang"
},
{
"elementId": "1310",
"field_allOverChallenge_allOverName": "AllOverChallenge2"
},
{
"elementId": "1318",
"field_allOverChallenge_allOverName": "Allover Challenge 3"
}
]
]
However, the Android-App accepts the JSON-String just with single square-brackets, like so:
[
{
"key":"value",
...
},
{
"key":"value",
...
}
]
For the sake of not having to change the existing Android-App, is it somehow possible to remove the additional square brackets?
Thanks.