Retrieving data poin from API response - php

I cobbled together some PHP code that allows me get business data from Yelp API v.3
$postData = "grant_type=client_credentials&".
"client_id=MyClientIDl94gqHAg&".
"client_secret=SomEcoDehIW09e6BGuBi4NlJ43HnnHl4S7W5eoXUkB";
// GET TOKEN
$curl = curl_init();
//set the url
curl_setopt($curl,CURLOPT_URL, "https://api.yelp.com/oauth2/token");
//tell curl we are doing a post
curl_setopt($curl,CURLOPT_POST, TRUE);
//set post fields
curl_setopt($curl,CURLOPT_POSTFIELDS, $postData);
//tell curl we want the returned data
curl_setopt($curl,CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($curl);
if($result){
$data = json_decode($result);
}
// GET RESTAURANT INFO
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.yelp.com/v3/businesses/north-india-restaurant-san-francisco",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$data->access_token
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
//close connection
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
The output looks like this:
{"id": "north-india-restaurant-san-francisco", "name": "North India Restaurant", "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/fIgAIMHGfWRF3I0JmagQ7A/o.jpg", "is_claimed": true, "is_closed": false, "url": "https://www.yelp.com/biz/north-india-restaurant-san-francisco?adjust_creative=qG_bVdazAjjAO1l94gqHAg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_lookup&utm_source=qG_bVdazAjjAO1l94gqHAg", "phone": "+14153481234", "display_phone": "(415) 348-1234", "review_count": 857, "categories": [{"alias": "indpak", "title": "Indian"}], "rating": 4.0, "location": {"address1": "123 Second St", "address2": "", "address3": "", "city": "San Francisco", "zip_code": "94105", "country": "US", "state": "CA", "display_address": ["123 Second St", "San Francisco, CA 94105"], "cross_streets": ""}, "coordinates": {"latitude": 37.787789124691, "longitude": -122.399305736113}, "photos": ["https://s3-media1.fl.yelpcdn.com/bphoto/howYvOKNPXU9A5KUahEXLA/o.jpg", "https://s3-media2.fl.yelpcdn.com/bphoto/I-CX8nioj3_ybAAYmhZcYg/o.jpg", "https://s3-media3.fl.yelpcdn.com/bphoto/uaSNfzJUiFDzMeSCwTcs-A/o.jpg"], "price": "$$", "hours": [{"open": [{"is_overnight": false, "start": "1000", "end": "2300", "day": 0}, {"is_overnight": false, "start": "1000", "end": "2300", "day": 1}, {"is_overnight": false, "start": "1000", "end": "2300", "day": 2}, {"is_overnight": false, "start": "1000", "end": "2300", "day": 3}, {"is_overnight": false, "start": "1000", "end": "0000", "day": 4}, {"is_overnight": false, "start": "1000", "end": "0000", "day": 5}, {"is_overnight": false, "start": "1000", "end": "2300", "day": 6}], "hours_type": "REGULAR", "is_open_now": true}], "transactions": ["delivery", "pickup"]}
How do I retrieve opening hour on Friday, for example? The day are 0 - 6, Monday - Sunday.

You parse the json data and iterate over the entries:
function getOpeningHoursForDay($data,$day){
$open_hours = $data['hours'][0]['open'];
$n = count($open_hours);
for($i=0;$i<$n;$i++){
if($open_hours[$i]['day']==$day) // check if day matches
return $open_hours[$i];
}
return null; // no matching day found, return null
}
function formatOpeningHour($hour){
return substr($hour,0,2).':'.substr($hour,2); // convert 2300 to 23:00
}
$data = json_decode($response,true);
$friday_hours = getOpeningHoursForDay($data,4);
if(isset($friday_hours)){
echo 'opened ' . formatOpeningHour($friday_hours['start']) . ' - ' .formatOpeningHour($friday_hours['end']);
}else{
echo 'closed';
}

Related

Getting 401 unauthorzed error while creating order with Shipstation REST API and PHP

I am trying to connect Shipstation with my website using REST API and creating order which can be added to manual store inside Shipstation by default. However, I am getting error 401 unauthorised continuously, even I copied API key and API secret from Shipstation account and passed its base64 form to Authorization header.
Here is my Simple Post Request :
$api_key = 'SS_KEY';
$api_secret = 'SS_SECRET';
$token = base64_encode($api_key.':'.$api_secret);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://ssapi.shipstation.com/orders/createorder/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"orderNumber": "TEST-ORDER-API-DOCS",
"orderStatus": "awaiting_shipment",
"customerUsername": "abc",
"customerEmail": "headhoncho#whitehouse.gov",
"billTo": {
"name": "Inam Ali",
"company": "abc",
"street1": "1",
"street2": null,
"street3": null,
"city": "Pesh",
"state": "KPK",
"postalCode": 25000,
"country": "Pakistan",
"phone": "0315333333",
"residential": true
},
"shipTo": {
"name": "Inam Ali",
"company": "US Govt",
"street1": "1600 Pennsylvania Ave",
"street2": "Oval Office",
"street3": null,
"city": "Washington",
"state": "DC",
"postalCode": "20500",
"country": "US",
"phone": "555-555-5555",
"residential": true
},
"items": [
{
"lineItemKey": "vd08-MSLbtx",
"name": "Test item #1",
"imageUrl": null,
"quantity": 2,
"unitPrice": 99.99,
"taxAmount": 2.5,
}
],
"amountPaid": 218.73,
"taxAmount": 5,
"tagIds": [
53974
]
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'host: ssapi.shipstation.com',
'Authorization: Basic '.$token
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

Foreach loop in Reviews.io API for Products

I'm very new to the world of APIs and am currently trying to display all reviews I have on my reviews.io account for a specific product. I've tried to make the following script, which now seems to work, however, I would love to have the results sorted nicely in a for-each loop.
Here my current script:
<?php
$header_data = array(
'store' => 'MYSHOP',
'apikey' => 'MYKEY',
'method' => 'GET'
);
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => 'https://api.reviews.co.uk/product/review?store=MYSHOP&sku=TSCB20&apikey=MYKEY',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $curlOpts);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
$rv = curl_exec($ch);
$data = json_decode($rv,true);
curl_close($ch);
?>
This outputs all reviews in Raw code or JSON I believe, however, I would like to have them displayed nicely in a div for each item.
The output is as follows (formatted):
{
"store": {
"name": "",
"logo": ""
},
"stats": {
"average": "5.0000",
"count": 2
},
"reviews": {
"total": 2,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"from": 1,
"to": 2,
"data": [
{
"votes": null,
"flags": null,
"title": "David",
"product_review_id": 2978412,
"review": "...is beautiful and I had a great time on this tour. Already started to plan my next trip with them",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "",
"timeago": "",
"reviewer": {
"first_name": "David",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "38677a4e8a55189055d6e5bf2efa9ade"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": "david#"
}
},
{
"votes": null,
"flags": null,
"title": null,
"product_review_id": 2978009,
"review": "Exceeded expectations on all fronts cultural and Food ",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "RGFY4ZG",
"timeago": "",
"reviewer": {
"first_name": "Alan",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "64e2ac644a158b76a82f9e1c5c2886f5"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": ""
}
}
]
},
"ratings": [],
"settings": {
"write_review_button": 1,
"disable_product_seo_css": 0,
"show_product_review_titles": 0
},
"word": "Excellent",
"products": [
{
"sku": "TSCB20",
"name": ""
}
],
"write_review_link": ""
}
My ideal outcome now would be a loop, that fetches the reviewer's name, the review itself and the star-rating. e.g.
<p class="review">Review here</p>
<p class="reviewer">Name here</p>
<p class="rating">Rating here</p>
So technically based on the current output, I should have 2 reviews. Some expert help would be greatly appreciated as I am very new to APIs. Thank you very much in advance.
Simple foreach() will do the job:
<?php foreach($data['reviews']['data'] as $dat){?>
<p class="review"><?php echo $dat['review'];?></p>
<p class="reviewer"><?php echo trim($dat['reviewer']['first_name'].' '.$dat['reviewer']['last_name']);?></p>
<p class="rating"><?php echo $dat['rating'];?></p>
<?php }?>

JSON and CURL encoding

I have a curl page that output in json format but I can't get json reading from android correctly. I want Json format with just an array only not object and array together. Check the output at the bottom for example. I want to write a php code that encode json that matches below. How would i do that? Thanks.
PHP FILE:
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/mashape/unirest-php/src/Unirest.php';
//$response = Unirest\Request::get("",
// array(
// "host" => "",
// "key" => "
// )
//);
//
//
//echo stripslashes(json_encode($response));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "json",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER, array('Accept: application/json'),
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"host: ",
"KEY: "
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$json = json_encode($response, JSON_UNESCAPED_SLASHES);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo stripslashes($response);
}
$fp = fopen('results.json', 'w');
fwrite($fp, stripslashes($response));
fclose($fp);
ORIGINAL OUTPUT FROM CURL:
{
"quoteResponse":
{
"result": [{
"language": "en-US",
"region": "US",
"quoteType": "EQUITY",
"quoteSourceName": "Nasdaq Real Time Price",
"exchangeDataDelayedBy": 0,
"regularMarketPrice": 30.69,
"regularMarketTime": 1568404801,
"regularMarketChange": 0.48000145,
"regularMarketVolume": 45547913,
"shortName": "Advanced Micro Devices, Inc.",
"priceHint": 2,
"postMarketChangePercent": 0.0325846,
"postMarketTime": 1568419190,
"postMarketPrice": 30.7,
"postMarketChange": 0.0100002,
"regularMarketChangePercent": 1.5888827,
"regularMarketPreviousClose": 30.21,
"fullExchangeName": "NasdaqGS",
"longName": "Advanced Micro Devices, Inc.",
"market": "us_market",
"pageViews": {
"shortTermTrend": "UP",
"midTermTrend": "UP",
"longTermTrend": "UP"
},
"marketState": "CLOSED",
"exchange": "NMS",
"sourceInterval": 15,
"exchangeTimezoneName": "America/New_York",
"exchangeTimezoneShortName": "EDT",
"gmtOffSetMilliseconds": -14400000,
"esgPopulated": false,
"tradeable": true,
"triggerable": true,
"symbol": "AMD"
}],
"error": null
}
}
THE OUTPUT I WANT IS THIS WITHOUT quoteResponse LIKE ABOVE OUTPUT. CHECK BELOW :
{
"result": [{
"language": "en-US",
"region": "US",
"quoteType": "EQUITY",
"quoteSourceName": "Nasdaq Real Time Price",
"regularMarketPrice": 30.69,
"regularMarketTime": 1568404801,
"regularMarketChange": 0.48000145,
"regularMarketVolume": 45547913,
"sourceInterval": 15,
"exchangeTimezoneName": "America/New_York",
"exchangeTimezoneShortName": "EDT",
"pageViews": {
"shortTermTrend": "UP",
"midTermTrend": "UP",
"longTermTrend": "UP"
},
"gmtOffSetMilliseconds": -14400000,
"market": "us_market",
"postMarketChangePercent": 0.0325846,
"postMarketTime": 1568419190,
"postMarketPrice": 30.7,
"postMarketChange": 0.0100002,
"regularMarketChangePercent": 1.5888827,
"priceHint": 2,
"shortName": "Advanced Micro Devices, Inc.",
"regularMarketPreviousClose": 30.21,
"fullExchangeName": "NasdaqGS",
"longName": "Advanced Micro Devices, Inc.",
"exchange": "NMS",
"exchangeDataDelayedBy": 0,
"esgPopulated": false,
"tradeable": true,
"triggerable": true,
"marketState": "CLOSED",
"symbol": "AMD"
}],
"error": null
}
Decode your JSON, get quoteResponse from it and encode it again.
$json = json_encode(json_decode($json)->quoteResponse);

How do I parse JSON arrays and retrieve PHP string variables? [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
Ok... so the following works so far:
// Open connection
$ch = curl_init();
// Make the curl call
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($head, true);
foreach($data['events'] as $key => $item) {
// $event_id = $data['events'][$key]['eventId'];
$event_id = $item['eventId'];
// $name = $data['events'][$key]['name'];
$name = $item['name'];
// $desc = $data['events'][$key]['description'];
$desc = $item['description'];
echo "ID: $event_id<br>
NAME: $name<br>
DESCRIPTION: $desc<br>
<br>";
}
However, I am trying multiple things and I am unable to capture "primaryImage" and "categories" data out of the arrays in the same JSON output and I am having difficulties with the syntax. Here is an example of the data:
{
"eventId": 5183191,
"name": "The Rhythm Rockets - FREE",
"description": "Summer Concert Series - The Rhythm Rockets . .\nFREE. Look for a YELLOW balloon. Bring a chair. PLEASE BE ON TIME (6:00 PM!) TO SIT WITH THE GROUP. Allow time for street parking. Expect a crowd. Meetup at 6pm - Showtime is 7pm. Food, wine and beer will be on sale.\nIn case of inclement weather, concerts will be held indoors at the Lincoln Center, 935 Maple Avenue. For weather updates, call[masked] after 5:30 pm. If moved inside, there is no way we can sit together.",
"primaryImage": {
"smallImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.small.png",
"mediumImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.medium.png",
"largeImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.large.png"
},
"categories": [{
"categoryId": 2,
"parentCategoryId": null,
"name": "Performing Arts"
}, {
"categoryId": 12,
"parentCategoryId": null,
"name": "Food & Drink"
}, {
"categoryId": 17,
"parentCategoryId": 2,
"name": "Music"
}, {
"categoryId": 75,
"parentCategoryId": 12,
"name": "Drinks"
}, {
"categoryId": 100,
"parentCategoryId": 17,
"name": "Concerts"
}],
"location": {
"latitude": 41.792683,
"longitude": -88.011765,
"city": "Downers Grove",
"state": "IL",
"address": "1000 Grove St",
"country": "United States",
"locationName": "Fishel Park"
},
"instances": [{
"startDateTime": "2018-08-21T18:00:00Z",
"endDateTime": null,
"hasTime": true,
"allDay": false
}],
"price": {
"lowerPrice": null,
"upperPrice": null,
"free": false,
"description": null
},
"lastUpdatedDate": "2018-07-26T02:20:49.686Z",
"popularity": null,
"interest": 50,
"links": [{
"isSponsor": false,
"name": "Meetup",
"linkUrl": "https://www.meetup.com/Im-Not-Dead-Yet-50-plus/events/252406255/",
"logoUrl": null
}, {
"isSponsor": true,
"name": "I'm Not Dead Yet --- 50+ Meetup",
"linkUrl": "http://Meetup.com/Im-Not-Dead-Yet-50-plus",
"logoUrl": null
}, {
"isSponsor": true,
"name": "I'm Not Dead Yet --- 50+ Meetup",
"linkUrl": "http://Meetup.com/Im-Not-Dead-Yet-50-plus",
"logoUrl": null
}],
"previousEventIds": [],
"seriesStart": "2018-08-21T18:00:00Z",
"seriesEnd": null,
"url": "http://portal.domainname.com/m/FireVite#!/details/THE-RHYTHM-ROCKETS-FREE/5183191/2018-08-21T18",
"handPicked": false,
"customField": null,
"contact": {
"organization": null,
"name": null,
"email": null,
"phone": null
},
"media": null
}
I would like to use data as PHP string variables that are found within elements such as "primaryImage", "categories", "location", etc.
Should be like this:
echo $item['primaryImage']->smallImageUrl;

Pullng Data From a JSON File From Fortnite Tracker API

I'm using the Fortnite Tracker API to get some data from my site, I have it working with by once connected it'll export my current data into a JSON file. This has worked fine for the mean time I have it working with a couple of the stats but for some reason I can't get it to work with recent matches, can someone see where I'm going wrong here?
PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/psn/mygamertag");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: myapikey'
));
$response = curl_exec($ch);
curl_close($ch);
$fp = fopen("myStats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("myStats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$matches = $data->recentMatches;//match data
$sesh1 = $matches[0]->id->valueInt;
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
$total_matches = ($solo_matches+$duos_matches+$squads_matches);
$total_wins = ($solo_wins+$duos_wins+$squads_wins);
$total_kills = ($solo_kills+$duos_kills+$squads_kills);
$total_kd = (round($total_kills/($total_matches-$total_wins),2));
echo 'Total Matches: '.$total_matches.'<br>';
echo 'Total Wins: '.$total_wins.'<br>';
echo 'Total Kills: '.$total_kills.'<br>';
echo 'Total KD: '.$total_kd.'<br>';
echo $sesh1;
?>
JSON File - Solo (This works fine with the PHP)
{
"stats": {
"p2": {
"score": {
"label": "Score",
"field": "Score",
"category": "General",
"valueInt": 31960,
"value": "31960",
"rank": 3045650,
"percentile": 47.0,
"displayValue": "31,960"
},
"top1": {
"label": "Wins",
"field": "Top1",
"category": "Tops",
"valueInt": 4,
"value": "4",
"rank": 1904807,
"percentile": 42.0,
"displayValue": "4"
},
"top3": {
"label": "Top 3",
"field": "Top3",
"category": "Tops",
"valueInt": 0,
"value": "0",
"rank": 1,
"displayValue": "0"
},
"top10": {
"label": "Top 10",
"field": "Top10",
"category": "Tops",
"valueInt": 44,
"value": "44",
"rank": 1923906,
"percentile": 9.0,
"displayValue": "44"
},
"top25": {
"label": "Top 25",
"field": "Top25",
"category": "Tops",
"valueInt": 79,
"value": "79",
"rank": 2519315,
"percentile": 11.0,
"displayValue": "79"
},
"kd": {
"label": "K/d",
"field": "KD",
"category": "General",
"valueDec": 0.71,
"value": "0.71",
"rank": 5155051,
"percentile": 63.0,
"displayValue": "0.71"
},
"matches": {
"label": "Matches",
"field": "Matches",
"category": "General",
"valueInt": 127,
"value": "127",
"rank": 4270142,
"percentile": 59.0,
"displayValue": "127"
},
"kills": {
"label": "Kills",
"field": "Kills",
"category": "General",
"valueInt": 87,
"value": "87",
"rank": 4376486,
"percentile": 58.0,
"displayValue": "87"
},
}
]
}
JSON File - Recent Matches (Struggling to pull data in the PHP)
{
"recentMatches": [
{
"id": 149942602,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 1,
"minutesPlayed": 0,
"top1": 0,
"top5": 0,
"top6": 0,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 1,
"top3": 0,
"dateCollected": "2018-04-18T08:09:28.963",
"score": 290,
"platform": 2,
"trnRating": 767.6,
"trnRatingChange": -103.23
},
{
"id": 148934320,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 1,
"minutesPlayed": 0,
"top1": 1,
"top5": 0,
"top6": 1,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 3,
"top3": 1,
"dateCollected": "2018-04-17T22:19:04.747",
"score": 865,
"platform": 2,
"trnRating": 870.8,
"trnRatingChange": -100.7124
},
{
"id": 147725308,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 0,
"minutesPlayed": 0,
"top1": 0,
"top5": 0,
"top6": 0,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 2,
"top3": 0,
"dateCollected": "2018-04-17T14:22:34.047",
"score": 423,
"platform": 2,
"trnRating": 906.0,
"trnRatingChange": -99.85293750000001
},
]
}
Being new to json, I had the same issue. To solve it I created a container for the recent matches.
$recent = $data->recentMatches;
This is an array of objects. So
echo $recent[1]->score;
would print '865', which is the score for the second match listed in your example.
Hope this helps.

Categories