This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 3 years ago.
[
{
"id":"8",
"product_slug":"",
"seller":"0x5144723b965a244af20ada1375b6d436441a4df4",
"buyer":"0x659d9e424b6f1ec5dbed9a2c96822ebe79be615a",
"message":"Hi, Smith do you want to buy my Infinix Note 4?",
"date_created":"2020-01-12 11:24:02",
"first_name":"Ebri",
"last_name":"Goodness"
}
]
that is a JSON array and you should decode it with json_decode($data, true) in PHP.
Related
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I have a Request in laravel where I pass a json object. The json is the following: { "firstname": "michael" }.
I am writing a dynamic search function and I want to store the data as 2 different values the "firstname" and the "michael". How can I do that in php ?
<?php
$array = json_decode('{"firstname":"michael"}', TRUE);
foreach ($array as $first => $second){
echo "first: {$first}\nsecond: {$second}";
}
Return:
first: firstname
second: michael
This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Closed 5 years ago.
How to extract json
{"scoreboard":{"lastUpdatedOn":"2017-08-21 6:58:49 PM","gameScore":[{"game":{"ID":"40380","week":"1","scheduleStatus":"Normal","originalDate":null,"originalTime":null,"delayedOrPostponedReason":null,"date":"2017-09-11","time":"7:10PM","awayTeam":{"ID":"70","City":"New Orleans","Name":"Saints","Abbreviation":"NO"},"homeTeam":{"ID":"63","City":"Minnesota","Name":"Vikings","Abbreviation":"MIN"},"location":"TCF Bank Stadium"},"isUnplayed":"true","isInProgress":"false","isCompleted":"false","quarterSummary":null}
How to extract above json by php
$allnfls = $nfls['scoreboard']['gameScore'];
foreach($allnfls as $allnfl)
{
//foreach($allnfld as $allnfl) {
$gameid = $allnfl['ID'];
echo "<br>".$week = $allnfl['game']['week'];
}
Define a variable and use json_decode(YourJSONString,true)
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 6 years ago.
how to access each file name...
{"Appointments":
[
{
"file_name":"eeea4a560492004c5c14f9414e88c32c.jpg",
"file_type":"image\/jpeg",
"file_path":"C:\/inetpub\/wwwroot\/nautSearch\/server\/uploadedfiles\/files\/",
"orig_name":"a46cf6866df6f358bece629ef472ac69.jpg",
"file_ext":".jpg",
"file_size":418.17,
"is_image":true,
"image_width":2560,
"image_height":1440,
"image_type":"jpeg",
"image_size_str":"width=\"2560\" height=\"1440\""
},
{
"file_name":"c08ff85a44e0f86ab48ec709e6ba1b4a.jpg",
"file_type":"image\/jpeg",
"file_path":"C:\/inetpub\/wwwroot\/nautSearch\/server\/uploadedfiles\/files\/",
"file_ext":".jpg",
"file_size":27.38,
"is_image":true,
"image_width":479,
"image_height":403,
"image_type":"jpeg",
"image_size_str":"width=\"479\" height=\"403\""
},
{
"file_name":"4536acd0479c6c5dee3b1f546ed8d328.jpg",
"file_type":"image\/jpeg",
"file_path":"C:\/inetpub\/wwwroot\/nautSearch\/server\/uploadedfiles\/files\/",
"file_ext":".jpg",
"file_size":27.38,
"is_image":true,
"image_width":479,
"image_height":403,
"image_type":"jpeg",
"image_size_str":"width=\"479\" height=\"403\""
}
]
}
What you gave is a json string. First you must decode it and loop over the appointments to use the file names:
$result = json_decode($yourJsonString);
foreach ($result->Appointments as $appointment) {
echo $appointment->file_name;
}
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 6 years ago.
How do I decode this json data using php to get individual values.
{"Alpha":["A","B","C","D","E","F"],"Beta":["1","2","3"],"Gamma": ["a","b","c"]}
php has a function called json_decode
$json = '{"Alpha":["A","B","C","D","E","F"],"Beta":["1","2","3"],"Gamma": ["a","b","c"]}';
$json_array = json_decode($json,TRUE); // personally I prefer arrays which the TRUE adds
$alpha = $json_array['Alpha'];
$first_alpha_value = $alpha[0];
printf("A == %s\n",$first_alpha_value);
This question already has answers here:
Get data from JSON file with PHP [duplicate]
(3 answers)
Closed 7 years ago.
How can i get ID value only?
like so here: $fo = "11890408";
{"success":true,"result":{"success":[{"id":"11890408","device_id":"17183","message":"okey","status":"pending","send_at":1455046054,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":1455049654,"canceled_at":0,"failed_at":0,"received_at":0,"error":"","created_at":1455046054,"contact":{"id":"2522330","name":"923336458112","number":"923336458112"}}],"fails":[]}}
Convert the json string to a php data structure and then navigate through the data tree of objects and arrays:
$json = '{
"success":true,
"result":{
"success[
{
"id":"11890408",
"device_id":"17183",
"message":"okey",
"status":"pending",
"send_at":1455046054,
"queued_at":0,
"sent_at":0,
"delivered_at":0,
"expires_at":1455049654,
"canceled_at":0,
"failed_at":0,
"received_at":0,
"error":"",
"created_at":1455046054,
"contact":{
"id":"2522330",
"name":"923336458112",
"number":"923336458112"
}
}
],
"fails":[]
}
}';
$data = json_decode($json);
$fo = $data->result->success[0]->id;