2

This is a json api : https://jobs.github.com/positions.json?description=java&page=1 I want get the data from this url.

<?php 
$url = file_get_contents('https://jobs.github.com/positions.json?description=java&page=1');
var_dump(json_decode($url,true));   ?>

this code return null I also check the url in json validator: http://jsonformatter.curiousconcept.com/ the json is valid but i con't able get the data from this url please help me...

3
  • Do you have error reporting enabled? Is $url really the JSON? Commented Jul 1, 2014 at 18:24
  • 1
    Your code works just fine for me! Don't you have JSON installed? What do you get, when you dump $url (which is actually not the URL, but the content data...)? Commented Jul 1, 2014 at 18:33
  • I get the result bro julian.I not enable the php_openssl in my php.ini so i couldn't get the result.Thank you for your help Commented Jul 2, 2014 at 8:57

1 Answer 1

2

Try this script to determine what the problem is. If there is no JSON module installed (see @julian comment), you can try to use PHP implementations of JSON like this: http://pear.php.net/pepr/pepr-proposal-show.php?id=198

if (! extension_loaded('json')) {
    echo 'Module JSON not available!';
    exit();
}

$url = file_get_contents('https://jobs.github.com/positions.json?description=java&page=1');
$data = json_decode($url,true);

switch (json_last_error()) {
    case JSON_ERROR_NONE:
        echo ' - No errors';
    break;
    case JSON_ERROR_DEPTH:
        echo ' - Maximum stack depth exceeded';
    break;
    case JSON_ERROR_STATE_MISMATCH:
        echo ' - Underflow or the modes mismatch';
    break;
    case JSON_ERROR_CTRL_CHAR:
        echo ' - Unexpected control character found';
    break;
    case JSON_ERROR_SYNTAX:
        echo ' - Syntax error, malformed JSON';
    break;
    case JSON_ERROR_UTF8:
        echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
    break;
    default:
        echo ' - Unknown error';
    break;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you kevin horst.Now i get the result.I not enable the php_openssl in my php.ini so i couldn't get the result.your code is help to achieve my result.jesus bless you

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.