I am currently in the process of requesting information from an API. When I try to decode the response of json with json_decode()
it doesn't give me the right data. When I use var_dump()
it does. How can I make my code correctly display the API data?
I have tried looking on the internet. I have used var_dump()
with succes yet it doesn't show the information right as with the dd()
.
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$json = json_decode($response);
}
This is the code I use to access the API data. This is the response with var_dump($json):
Example: array(344) {
[0]=>
object(stdClass)#1148 (1) {
["product"]=>
object(stdClass)#1141 (3) {
["information"]=>
object(stdClass)#1140 (1) {
["deliveryDays"]=>
string(2) "10"
}
["attributes"]=>
array(6) {
[0]=>
object(stdClass)#1142 (2) {
["attribute"]=>
string(18) "Type of sunglasses"
["value"]=>
string(5) "basic"
}
[1]=>
object(stdClass)#1143 (2) {
["attribute"]=>
string(15) "variantid (mcp)"
["value"]=>
string(9) "P105675W1"
}
[2]=>
object(stdClass)#1144 (2) {
["attribute"]=>
string(11) "color (mcp)"
["value"]=>
string(17) "Solid Black/White"
}
[3]=>
object(stdClass)#1145 (2) {
["attribute"]=>
string(8) "quantity"
["value"]=>
string(3) "100"
}
[4]=>
object(stdClass)#1146 (2) {
["attribute"]=>
string(16) "printing process"
["value"]=>
string(12) "tampon print"
}
[5]=>
object(stdClass)#1147 (2) {
["attribute"]=>
string(13) "delivery type"
["value"]=>
string(6) "normal"
}
}
["price"]=>
float(213.3)
}
}
When I use dd($json)
:
+"product": {#1150 ▼
+"information": {#1149 ▶}
+"attributes": array:6 [▼
0 => {#1151 …2}
1 => {#1152 …2}
2 => {#1153 …2}
3 => {#1154 …2}
4 => {#1155 …2}
5 => {#1156 …2}
]
+"price": 407.7
}
As you can see, the API shows ...2 in array 6 but it should show a value. What is wrong about my code?
I want the API to dd the data correctly and show me the data in the api
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2IbQl5N
via IFTTT
Aucun commentaire:
Enregistrer un commentaire