Hi I want JSON response in below format using PHP.
{
"response": {
"status": "ok",
"results": [
{
"id": "123",
"fields": {
"trailText": "SomeText",
"thumbnail": "URL"
},
"tags": [
{
"id": "profile/amy-walker",
"type": "contributor",
]
}
]
}
}
My PHP Code
while($row = mysqli_fetch_assoc($result1))
{
$temp_array[$num_rows]['id']= $row["id"];
//Some more code
}
echo $post = json_encode(array('response'=>$myObj,$temp_array));
But I got response like this
{
"response": {
"status": "ok"
},
"results": [
{
"id": "123",
"fields": {
"trailText": "SomeText",
"thumbnail": "URL"
},
"tags": [
{
"id": "profile/amy-walker",
"type": "contributor",
]
}
]
}
I want my array should be bound inside response.
$myObj is
object(stdClass)#4 (8) {
["status"]=> string(2) "ok"
["userTier"]=> string(9) "developer"
["total"]=> int(8282)
["startIndex"]=> int(1)
["pageSize"]=> int(12)
["currentPage"]=> int(1)
["pages"]=> int(8282)
["orderBy"]=> string(6) "newest"
}
json_encode(array('response'=>array($myObj,$temp_array)))to group together the last bits of data (i.e. add an extraarray()in)$myObjby doingvar_dump($myObj);json_encodeproduces a different output, then your input data is in the wrong format