JSON php parsing trouble2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?Parse JSON in JavaScript?how can i check if RESTAPI is down using curl php
Nested Dynamic SOQL Query
How to read string as hex number in bash?
"Marked down as someone wanting to sell shares." What does that mean?
Why is participating in the European Parliamentary elections used as a threat?
Is there any common country to visit for uk and schengen visa?
Animating wave motion in water
Do I need to convey a moral for each of my blog post?
Does fire aspect on a sword, destroy mob drops?
What are the consequences of changing the number of hours in a day?
How to test the sharpness of a knife?
Knife as defense against stray dogs
Why is "la Gestapo" feminine?
How to understand 「僕は誰より彼女が好きなんだ。」
Fair way to split coins
Hot air balloons as primitive bombers
What kind of footwear is suitable for walking in micro gravity environment?
Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?
Homology of the fiber
Are hand made posters acceptable in Academia?
The English Debate
Unfrosted light bulb
When should a starting writer get his own webpage?
What is the tangent at a sharp point on a curve?
Turning a hard to access nut?
JSON php parsing trouble
2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?Parse JSON in JavaScript?how can i check if RESTAPI is down using curl php
I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error
Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
php json
|
show 1 more comment
I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error
Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
php json
json_decode()
is failing for some reason.
– Barmar
Mar 7 at 18:59
1
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
1
Tryvar_dump($response)
to see what you're getting.
– Barmar
Mar 7 at 19:01
1
You should check$curl_errno
before you try to use$response
.
– Barmar
Mar 7 at 19:01
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17
|
show 1 more comment
I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error
Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
php json
I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error
Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
php json
php json
edited Mar 7 at 19:00
Barmar
433k36256357
433k36256357
asked Mar 7 at 18:56
johncsmith427johncsmith427
185
185
json_decode()
is failing for some reason.
– Barmar
Mar 7 at 18:59
1
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
1
Tryvar_dump($response)
to see what you're getting.
– Barmar
Mar 7 at 19:01
1
You should check$curl_errno
before you try to use$response
.
– Barmar
Mar 7 at 19:01
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17
|
show 1 more comment
json_decode()
is failing for some reason.
– Barmar
Mar 7 at 18:59
1
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
1
Tryvar_dump($response)
to see what you're getting.
– Barmar
Mar 7 at 19:01
1
You should check$curl_errno
before you try to use$response
.
– Barmar
Mar 7 at 19:01
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17
json_decode()
is failing for some reason.– Barmar
Mar 7 at 18:59
json_decode()
is failing for some reason.– Barmar
Mar 7 at 18:59
1
1
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
1
1
Try
var_dump($response)
to see what you're getting.– Barmar
Mar 7 at 19:01
Try
var_dump($response)
to see what you're getting.– Barmar
Mar 7 at 19:01
1
1
You should check
$curl_errno
before you try to use $response
.– Barmar
Mar 7 at 19:01
You should check
$curl_errno
before you try to use $response
.– Barmar
Mar 7 at 19:01
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17
|
show 1 more comment
1 Answer
1
active
oldest
votes
I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050963%2fjson-php-parsing-trouble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
add a comment |
I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
add a comment |
I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.
<?php
$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];
foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);
if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";
if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;
file_put_contents("ids.txt", implode(PHP_EOL,$newids));
?>
answered Mar 7 at 19:11
joyjoy
796620
796620
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
add a comment |
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link
– johncsmith427
Mar 7 at 19:16
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data
– joy
Mar 7 at 19:38
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.
– joy
Mar 7 at 19:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050963%2fjson-php-parsing-trouble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
json_decode()
is failing for some reason.– Barmar
Mar 7 at 18:59
1
gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue
– joy
Mar 7 at 18:59
1
Try
var_dump($response)
to see what you're getting.– Barmar
Mar 7 at 19:01
1
You should check
$curl_errno
before you try to use$response
.– Barmar
Mar 7 at 19:01
Here is a link to the actual file link
– johncsmith427
Mar 7 at 19:17