Reputation: 23
PHP->JSON
So I'm calling an online service that returns a JSON to which I'm decoding. Then for each record, I'm STRPOS against one field, and if !== FALSE, I want it to display the record, else go to next record.
ISSUE: Without the STRPOS, all the code works and doesn't timeout. With STRPOS, I'm getting a 500 error.
Is it my code (inefficient) or is the service timing me out maybe? Thoughts?
Thanks in advance!
$jsonFile = file_get_contents('https://api.website.com/file.json');
$json_outputa = json_decode($jsonFile);
foreach ( $json_outputa->divisions as $division )
{
$jsondeal = file_get_contents('https://api.website.com/specifics.json?division_id=' . $division->id . '&filters=category:' . $category . '&limit=20');
$jsondeal_output = json_decode($jsondeal);
foreach ( $jsondeal_output->deals as $deal )
{
If ($deal->tags)
{
If (strpos($deal->Title, $searchstring) !== false)
{
?>
<tr>
!! NOW DO STUFF !!
*! The Code that works and returns to the UI. Just the IF with STRPOS removed.
$jsonFile = file_get_contents('https://api.website.com/file.json');
$json_outputa = json_decode($jsonFile);
foreach ( $json_outputa->divisions as $division )
{
$jsondeal = file_get_contents('https://api.website.com/specifics.json?division_id=' . $division->id . '&filters=category:' . $category . '&limit=20');
$jsondeal_output = json_decode($jsondeal);
foreach ( $jsondeal_output->deals as $deal )
{
If ($deal->tags)
{
?>
Upvotes: 1
Views: 63
Reputation: 1
I think its is your link https://api.website.com/file.json try opening it in browser it says 404 file not found.
try a local json or something valid JSON file like this one
http://www.json-generator.com/api/json/get/cbvSOJYRbC?indent=2
Upvotes: -1