I've got some sort of encoding issue when trying to retrieve a third-party feed, which when using json_last_error()
reports back with Unexpected control character found
.
From what I've read, this can be caused by a non UTF-8 character appearing in the mix.
I've run the copied JSON through a linter, and is valid. Copy/pasting the JSON from the remote feed into a string and decoding that way works fine, just not when directly accessing via file_get_contents
.
{
"numberOfResults": 124,
"queryTime": 0,
"products": [
{
"productId": "9130047$0290f955-ce36-46c9-9771-184f05985c62",
"status": null,
"serviceId": null,
"productName": null,
"serviceName": null,
"productDescription": null,
"serviceDescription": null,
"productCategoryId": null,
"nearestLocation": null,
"boundary": null,
"distanceToLocation": null,
"startDate": null,
"endDate": null,
"productImage": null,
"serviceImage": null,
"tqual": null,
"trip_advisor": null,
"freeEntry": null,
"booster": null,
"starRating": null,
"rateFrom": null,
"rateTo": null,
"productClassifications": null,
"internet_service_ssid": null,
"internet_service_type": null,
"linked_productid": null,
"states": null,
"suburbs": null,
"addresses": null,
"cities": null,
"comms_em": null,
"comms_mb": null,
"comms_burl": null,
"comms_url": null,
"comms_ph": null,
"comms_fx": null,
"comms_wap": null,
"internet_points": null
}
],
"facetGroups": []
}
And just a simple decode...
$raw = file_get_contents($url);
$result = json_decode($raw, false);
// json_last_error() shows JSON_ERROR_CTRL_CHAR