0

I want to get json from url but when i try the dd($data) i got parse error on line 1: bla bla expect string error.

First, i doubted with my json object is invalid then i tried with jsontest object but i got still same error. Here is the simple code:

    $stationData = file_get_contents("http://ip.jsontest.com/");
    $stationData = json_decode($stationData);
    dd($stationData);

And, this is the error message:

Error: Parse error on line 1:
{#149 ▼  +"ip": "95.
-^
Expecting 'STRING', '}'

If i use json_decode($data, true) i got valid array instead of json object.

What's wrong with this?

16
  • what happens when you do print_r for example print_r($stationData->ip); instead of dd($stationData)? Commented May 29, 2016 at 16:08
  • I've executed your code just right now? And no errors occurred. My output {#144 ▼ +"ip": "104.155.78.120" } Commented May 29, 2016 at 16:08
  • @huuuk executed with laravel? Commented May 29, 2016 at 16:09
  • Yes. I think there are an error in other place of your code. Commented May 29, 2016 at 16:10
  • There is no code other than.. interesting, maybe its about apache error, i will try with remote right now Commented May 29, 2016 at 16:11

1 Answer 1

2

As huuk and PeterPan666 said this is not laravel error. I was using jsonformatter plugin with my chrome, error was coming from plugin. It solved. Thanks for helping.

Sign up to request clarification or add additional context in comments.

1 Comment

Same issue I am facing from last 2 days and finally your answer helps me to resolve the issue.. thanks man :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.