Json needs a root.. So brackets are needed. Why would they need to be removed?
How to remove brackets wrapper in api resource responses
Hello friends How to remove brackets wrapper in api resource responses for example now
{
"data": {
.........
}
}
i NEED TO DO IT LIKE THIS
"data": {
.........
}
@Sinnbeck Android Developer Need do that shape in response so it's it's not possibale sir ?!!!
@Respect Can you show a working example here? https://jsonformatter.curiousconcept.com/
You can try opening your browser console (F12->console). Paste this in and hit enter
const myvar = {
"data": {
"bar": "foo",
}
};
You can now access data on myvar.data
i got this response
{
"data":{
"result":"success",
"message":"",
"data":[
{
"id":1,
"name":"Category Number 0",
"icon":"path",
"color":"blue"
},
{
"id":2,
"name":"Category Number 0",
"icon":"path",
"color":"red"
},
]
}
}
i need to remove first {} to make the data as first object look that
"data":{
"result":"success",
"message":"",
"data":[
{
"id":1,
"name":"Category Number 0",
"icon":"path",
"color":"blue"
},
{
"id":2,
"name":"Category Number 0",
"icon":"path",
"color":"red"
},
]
}
*code in controller
$categories = Category::select('id',toLocale('name'),'color')->get();
// just to can append result and message
return response()->json(['data' => new CategoryCollection($categories)], 200);
// return new CategoryCollection($categories);
- code in api resource
return [
'result' => 'success',
'message' => '',
'data' => $this->collection,
];
@Respect It already is as you want it. The other {} just tells the JSON parser that its an object.
Does the android developer perhaps mean that it should not be wrapped in data?
{
"result":"success",
"message":"",
"data":[
{
"id":1,
"name":"Category Number 0",
"icon":"path",
"color":"blue"
},
{
"id":2,
"name":"Category Number 0",
"icon":"path",
"color":"red"
},
]
@Sinnbeckfirst of all thanks sir for your time and help - i sent the answer to him and waiting his answer can i keep the answer open untill i get his answer back than i will mark it okey sir
@Respect Maybe send him the link to this thread? Then he can perhaps come and explain what he needs :)
@Sinnbeck ok sir i will send it to him --- Thanks Again for your time and help later will mark your answer
Please or to participate in this conversation.