0
I have the following . Json
object(stdClass)#1 (4) {
["card-header"]=>
object(stdClass)#2 (5) {
["raceId"]=>
string(7) "1706057"
["races"]=>
object(stdClass)#3 (1) {
["95049"]=>
object(stdClass)#4 (6) {
["meeting_abandoned"]=>
int(0)
["track"]=>
string(8) "Kilkenny"
["races"]=>
array(10) {
[0]=>
object(stdClass)#5 (3) {
["raceId"]=>
string(7) "1706057"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "8:12"
}
[1]=>
object(stdClass)#6 (3) {
["raceId"]=>
string(7) "1706058"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "8:27"
}
[2]=>
object(stdClass)#7 (3) {
["raceId"]=>
string(7) "1706059"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "8:43"
}
[3]=>
object(stdClass)#8 (3) {
["raceId"]=>
string(7) "1706060"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "9:02"
}
[4]=>
object(stdClass)#9 (3) {
["raceId"]=>
string(7) "1706857"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "9:18"
}
[5]=>
object(stdClass)#10 (3) {
["raceId"]=>
string(7) "1706858"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "9:34"
}
[6]=>
object(stdClass)#11 (3) {
["raceId"]=>
string(7) "1706859"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(4) "9:52"
}
[7]=>
object(stdClass)#12 (3) {
["raceId"]=>
string(7) "1706860"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(5) "10:07"
}
[8]=>
object(stdClass)#13 (3) {
["raceId"]=>
string(7) "1706861"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(5) "10:23"
}
[9]=>
object(stdClass)#14 (3) {
["raceId"]=>
string(7) "1706862"
["raceDate"]=>
string(10) "2019-07-03"
["raceTime"]=>
string(5) "10:41"
}
}
["track_id"]=>
string(2) "50"
["tv_id"]=>
string(0) ""
["tv_name"]=>
string(0) ""
}
}
["courseId"]=>
int(95049)
["country"]=>
string(3) "IRE"
["trackAbbrName"]=>
string(7) "K'kenny"
}
["card-title"]=>
object(stdClass)#15 (16) {
["postPick"]=>
string(5) "6-5-3"
["napNum"]=>
string(0) ""
["raceSisStatusTopicD5"]=>
string(48) "GREYHOUNDS/2019-07-03/KILKENNY/08:12/#SIS_STATUS"
["infoTopicD5"]=>
string(78) "GREYHOUNDS/2019-07-03/KILKENNY/08:12/OUTRIGHT WINNER/#INFO/PREFERRED_BOOKMAKER"
["priceTopicD5"]=>
string(86) "GREYHOUNDS/2019-07-03/KILKENNY/08:12/OUTRIGHT WINNER/PREFERRED_DOG/PREFERRED_BOOKMAKER"
["testingPriceTopic"]=>
string(86) "GREYHOUNDS/2019-07-03/KILKENNY/08:12/OUTRIGHT WINNER/PREFERRED_DOG/PREFERRED_BOOKMAKER"
["distance"]=>
int(480)
["raceGrade"]=>
string(2) "A9"
["raceTypeDesc"]=>
string(4) "Flat"
["raceDatetime"]=>
string(10) "1562137920"
["raceHour"]=>
string(2) "08"
["raceMin"]=>
string(2) "12"
["reserved"]=>
string(0) ""
["tvId"]=>
string(0) ""
["bagsCode"]=>
string(1) "S"
["raceTitle"]=>
string(6) "Race 1"
}
["card-tabs"]=>
object(stdClass)#16 (20) {
["raceId"]=>
string(7) "1706057"
["raceDate"]=>
string(16) "2019-07-03 08:12"
["distance"]=>
string(3) "480"
["raceStatus"]=>
int(0)
["raceTitle"]=>
string(32) "Welcome To Kilkenny Track A9 525"
["bagsCode"]=>
string(1) "S"
["trackName"]=>
string(8) "KILKENNY"
["trackCde"]=>
string(4) "KILK"
["rpTrackShortName"]=>
string(5) "Kilky"
["trackId"]=>
string(2) "50"
["country"]=>
string(3) "IRE"
["typeDesc"]=>
string(4) "Flat"
["raceGrade"]=>
string(2) "A9"
["selTrapNum"]=>
string(1) "6"
["tvId"]=>
string(0) ""
["dangerTrapNum"]=>
string(1) "5"
["fcastAltTrapNum"]=>
string(1) "3"
["napNum"]=>
string(0) ""
["raceDateDate"]=>
string(10) "2019-07-03"
["raceDateTime"]=>
string(5) "08:12"
}
["card"]=>
object(stdClass)#17 (1) {
["dogs"]=>
array(6) {
[0]=>
object(stdClass)#18 (28) {
["dogId"]=>
string(6) "528848"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "1"
["dogName"]=>
string(14) "Flexible Pango"
["dogColor"]=>
string(2) "BK"
["dogSex"]=>
string(1) "B"
["forecastComment"]=>
string(42) "Been battered around lately, due some luck"
["chanceOfWin"]=>
float(30.72)
["trainerName"]=>
string(9) "M Kennedy"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "5/1"
["topSpeed"]=>
string(2) "93"
["wideYn"]=>
string(0) ""
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(14) "FLEXIBLE_PANGO"
["spotlightComment"]=>
string(42) "Been battered around lately, due some luck"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(6) "1Sep15"
["brt"]=>
string(5) "30.57"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(12) "Farloe Tango"
["dam"]=>
string(13) "Flexible Dora"
["birthMonYY"]=>
string(5) "Sep15"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "53355"
}
[1]=>
object(stdClass)#19 (28) {
["dogId"]=>
string(6) "532977"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "2"
["dogName"]=>
string(13) "Bradys Choice"
["dogColor"]=>
string(2) "BK"
["dogSex"]=>
string(1) "B"
["forecastComment"]=>
string(51) "Finding trouble, not showcasing ability as a result"
["chanceOfWin"]=>
float(30.78)
["trainerName"]=>
string(9) "M Fortune"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "5/1"
["topSpeed"]=>
string(2) "91"
["wideYn"]=>
string(0) ""
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(13) "BRADYS_CHOICE"
["spotlightComment"]=>
string(51) "Finding trouble, not showcasing ability as a result"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(7) "11Jan18"
["brt"]=>
string(5) "30.67"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(13) "Ballymac Eske"
["dam"]=>
string(12) "Marinas Blue"
["birthMonYY"]=>
string(5) "Jan18"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "T5666"
}
[2]=>
object(stdClass)#20 (28) {
["dogId"]=>
string(6) "528978"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "3"
["dogName"]=>
string(13) "Littlest Hobo"
["dogColor"]=>
string(3) "WBK"
["dogSex"]=>
string(1) "B"
["forecastComment"]=>
string(54) "Learning twists and turns of track, may still run well"
["chanceOfWin"]=>
float(30.42)
["trainerName"]=>
string(9) "D Fogarty"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "4/1"
["topSpeed"]=>
string(2) "99"
["wideYn"]=>
string(0) ""
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(13) "LITTLEST_HOBO"
["spotlightComment"]=>
string(54) "Learning twists and turns of track, may still run well"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(6) "1May17"
["brt"]=>
string(5) "30.31"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(14) "Sidarian Blaze"
["dam"]=>
string(14) "Miss Precedent"
["birthMonYY"]=>
string(5) "May17"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "532T3"
}
[3]=>
object(stdClass)#21 (28) {
["dogId"]=>
string(6) "532964"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "4"
["dogName"]=>
string(9) "Amwhatiam"
["dogColor"]=>
string(2) "BE"
["dogSex"]=>
string(1) "B"
["forecastComment"]=>
string(49) "Luck tends to even itself out, due a change of it"
["chanceOfWin"]=>
float(30.51)
["trainerName"]=>
string(11) "S O'Donnell"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "7/2"
["topSpeed"]=>
string(2) "96"
["wideYn"]=>
string(0) ""
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(9) "AMWHATIAM"
["spotlightComment"]=>
string(49) "Luck tends to even itself out, due a change of it"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(7) "12Sep17"
["brt"]=>
string(4) "30.4"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(16) "Superior Product"
["dam"]=>
string(12) "Aclamon Jill"
["birthMonYY"]=>
string(5) "Sep17"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "TTT64"
}
[4]=>
object(stdClass)#22 (28) {
["dogId"]=>
string(6) "528832"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "5"
["dogName"]=>
string(16) "Heyisntthatright"
["dogColor"]=>
string(2) "BK"
["dogSex"]=>
string(1) "B"
["forecastComment"]=>
string(47) "Five alive? Must be paw perfect to avoid a bang"
["chanceOfWin"]=>
float(30.33)
["trainerName"]=>
string(14) "M Bergin-Flynn"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "7/2"
["topSpeed"]=>
string(3) "100"
["wideYn"]=>
string(0) ""
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(16) "HEYISNTTHATRIGHT"
["spotlightComment"]=>
string(47) "Five alive? Must be paw perfect to avoid a bang"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(7) "15Aug17"
["brt"]=>
string(5) "30.13"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(14) "Barefoot James"
["dam"]=>
string(8) "Hey Ruby"
["birthMonYY"]=>
string(5) "Aug17"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "44336"
}
[5]=>
object(stdClass)#23 (28) {
["dogId"]=>
string(6) "533139"
["trackId"]=>
string(2) "50"
["trapNum"]=>
string(1) "6"
["dogName"]=>
string(14) "Kilbreedy Hulk"
["dogColor"]=>
string(2) "BK"
["dogSex"]=>
string(1) "D"
["forecastComment"]=>
string(45) "Being backed with good reason, leading player"
["chanceOfWin"]=>
float(30.29)
["trainerName"]=>
string(8) "F Hickey"
["trainerLocation"]=>
string(0) ""
["forecast"]=>
string(3) "9/4"
["topSpeed"]=>
string(2) "99"
["wideYn"]=>
string(1) "M"
["handicapMetre"]=>
string(0) ""
["diffusionName"]=>
string(14) "KILBREEDY_HULK"
["spotlightComment"]=>
string(45) "Being backed with good reason, leading player"
["nonRunner"]=>
string(0) ""
["reserved"]=>
string(0) ""
["isVacant"]=>
string(0) ""
["dateOfBirth"]=>
string(7) "21Oct17"
["brt"]=>
string(5) "30.23"
["bestTimeGrade"]=>
string(0) ""
["bestTimeGradeDate"]=>
string(0) ""
["sire"]=>
string(12) "Farloe Blitz"
["dam"]=>
string(14) "Garryglass Ros"
["birthMonYY"]=>
string(5) "Oct17"
["dateOfSeason"]=>
string(0) ""
["shortForm"]=>
string(5) "T6326"
}
}
}
}
I’m having trouble picking up items belonging to only one object specifically...
For example, I have the [card-header], [card-title], [card-tabs] and [card]...
When accessing for example, the [card-title]->postPick
, I have the following problem...
If access like this:
foreach($itens->card-title as $dados){
echo $dados->postPick;
}
Warning: Invalid argument supplied for foreach()
If you do not direct the object and access it thus:
foreach($itens as $dados){
echo "Resultado".$dados->postPick."<br>";
}
I print the data and see that the foreach()
traversed the entire json, and prints a "result" for each object... for example...
Resultado: (nao presente no [card-header]
Resultado: 6-5-3 (presente apenas no [card-title]
Resultado: (não presente no [card-tabs]
Resultado: (não presente no card)
theoretically it should appear only the second result, because it is the only place where the object is present...
In short, how can I access separately these objects and I receive this Warning when I try to orient inside the foreach()
? Could the problem be the hyphen in the object name, type [card-title] and causes this syntax error? I did all the process with the object [card] and it worked perfectly, so I’m believing it...
ps: I don’t want to transfer json to array, I tried and had more difficulty yet.
Because you do not change from "card-header" to "cardHeader", and "card-title" to "cardTitle", etc... the way you are using can give problems when using object, just use an alias, in case...
– Ivan Ferrer
I think it’s something like this to work:
if (count($seu_objeto->{"card-header"}->raceId->races->95049->meeting_abandoned->races)) {
 $races = $seu_objeto->{"card-header"}->raceId->races->95049->meeting_abandoned->races;
 foreach($races as $race) {

 $race->raceId;
 ...
 }
}
– Ivan Ferrer
See here an example
– Ivan Ferrer
I even tried to remove the hyphen, but it turns out that the json is dynamic and taken from another server... But anyway, I was able to get rid of the duplicate and null values as follows
if($dados->raceId != NULL){$raceid = $dados->raceId; }
, playing the non-zero values for a variable, but, I will try to do the way you proposed, I did not know! -– Lucas Araujo