0

I am consuming a webservice in PHP , below is code sample

>         if ( $datas=file_get_contents($url) ) return json_decode($datas);
>         return Array('error' => "Can't open url");

I return the the value of above function call to js page. but I dont get the value of webservice call in js but always get error value. However if I open the $url in browser I get below data (valid json) :

{"d":[ [ 5.305,428 ] ] }

Due to framework restriction i can use only json_decode() to return values back to my js page. I also tried json_decode($datas,true); but still no help.

I also tried consuming same code in standalone php file : I get this error : when I use json_decode($datas)

Catchable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\webservice-demo\clientRestTest.php on line 32

and below error if I use json_decode($datas,true);

Notice: Array to string conversion in C:\xampp\htdocs\webservice-demo\clientRestTest.php on line 32 Array

Please let me know how to resolve the issue .

1 Answer 1

0

Is there any special chars in $url? if there is, try urlencoding it first

file_get_contents(urlencode($url)); etc etc

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

Comments

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.