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)
Related
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.
This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I got a JSON from an URL like this:
http://myweb.com/ws_clc/ws_info.php?uid=77317
JSON:
{
"status":1,
"info":[
{
"uid":"77317",
"name":"Jack",
"lastname":"Black",
"email":"jackblack#mail.com"
}
]
}
I need to format that JSON on HTML.
¿How can I do that?
THANKS!!! I did it like this:
<?php
$uid =$_GET['uid'];
$json = file_get_contents('http://myweb.com/ws_clc/ws_info.php?uid='.$uid);
$obj = json_decode($json);
$uid= $obj->info[0]->uid;
$name = $obj->info[0]->name;
$lastname = $obj->info[0]->lastname;
echo $name;
echo $lastname;
?>
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;
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php loop through associative arrays
i have this piece of code which gets me as an output an array like this here:
http://penelope-ns.net/fb/fig.jpg
How can i save the [name] as a variable $name?
The code i use to generate is this:
$fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); ///// Add this line
As far as I can see:
$fbid = 500591729;
$name = $array[$fbid] ['data'] [0] ['name'];
Or for all names:
foreach ($array as $fbid=>$value) {
echo $value['data'][0]['name'];
}