json_decode giving null on a valid json












0















I have this text in my $result




{"meta":{"code":400,"message":"Bad Request"},"error":"userId is required.","extras":null}




But when I do



$json_result = json_decode($result, true);
print_r($json_result);


It gives me null. I have validated this text everywhere and it says that it is a valid json.



EDIT



This is my code



<?php

$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
echo '<hr>';
curl_close($ch);
$json_result = json_decode($result, true);
echo json_last_error_msg();
echo '<hr>';
//$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
print_r($json_result);
?>









share|improve this question

























  • What does json_last_error_msg tell you?

    – Paul
    Nov 13 '18 at 11:08











  • It says 4 but I don't understand why does it say 4

    – Ali Zia
    Nov 13 '18 at 11:09






  • 4





    Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

    – Nick
    Nov 13 '18 at 11:09











  • No just this text

    – Ali Zia
    Nov 13 '18 at 11:10











  • 4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

    – Utkanos
    Nov 13 '18 at 11:11


















0















I have this text in my $result




{"meta":{"code":400,"message":"Bad Request"},"error":"userId is required.","extras":null}




But when I do



$json_result = json_decode($result, true);
print_r($json_result);


It gives me null. I have validated this text everywhere and it says that it is a valid json.



EDIT



This is my code



<?php

$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
echo '<hr>';
curl_close($ch);
$json_result = json_decode($result, true);
echo json_last_error_msg();
echo '<hr>';
//$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
print_r($json_result);
?>









share|improve this question

























  • What does json_last_error_msg tell you?

    – Paul
    Nov 13 '18 at 11:08











  • It says 4 but I don't understand why does it say 4

    – Ali Zia
    Nov 13 '18 at 11:09






  • 4





    Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

    – Nick
    Nov 13 '18 at 11:09











  • No just this text

    – Ali Zia
    Nov 13 '18 at 11:10











  • 4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

    – Utkanos
    Nov 13 '18 at 11:11
















0












0








0








I have this text in my $result




{"meta":{"code":400,"message":"Bad Request"},"error":"userId is required.","extras":null}




But when I do



$json_result = json_decode($result, true);
print_r($json_result);


It gives me null. I have validated this text everywhere and it says that it is a valid json.



EDIT



This is my code



<?php

$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
echo '<hr>';
curl_close($ch);
$json_result = json_decode($result, true);
echo json_last_error_msg();
echo '<hr>';
//$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
print_r($json_result);
?>









share|improve this question
















I have this text in my $result




{"meta":{"code":400,"message":"Bad Request"},"error":"userId is required.","extras":null}




But when I do



$json_result = json_decode($result, true);
print_r($json_result);


It gives me null. I have validated this text everywhere and it says that it is a valid json.



EDIT



This is my code



<?php

$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
echo '<hr>';
curl_close($ch);
$json_result = json_decode($result, true);
echo json_last_error_msg();
echo '<hr>';
//$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
print_r($json_result);
?>






php json curl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:38









ADyson

23.6k112445




23.6k112445










asked Nov 13 '18 at 11:07









Ali ZiaAli Zia

2,3491841




2,3491841













  • What does json_last_error_msg tell you?

    – Paul
    Nov 13 '18 at 11:08











  • It says 4 but I don't understand why does it say 4

    – Ali Zia
    Nov 13 '18 at 11:09






  • 4





    Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

    – Nick
    Nov 13 '18 at 11:09











  • No just this text

    – Ali Zia
    Nov 13 '18 at 11:10











  • 4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

    – Utkanos
    Nov 13 '18 at 11:11





















  • What does json_last_error_msg tell you?

    – Paul
    Nov 13 '18 at 11:08











  • It says 4 but I don't understand why does it say 4

    – Ali Zia
    Nov 13 '18 at 11:09






  • 4





    Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

    – Nick
    Nov 13 '18 at 11:09











  • No just this text

    – Ali Zia
    Nov 13 '18 at 11:10











  • 4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

    – Utkanos
    Nov 13 '18 at 11:11



















What does json_last_error_msg tell you?

– Paul
Nov 13 '18 at 11:08





What does json_last_error_msg tell you?

– Paul
Nov 13 '18 at 11:08













It says 4 but I don't understand why does it say 4

– Ali Zia
Nov 13 '18 at 11:09





It says 4 but I don't understand why does it say 4

– Ali Zia
Nov 13 '18 at 11:09




4




4





Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

– Nick
Nov 13 '18 at 11:09





Works for me on pretty much all PHP versions: 3v4l.org/KNUdP perhaps you have some non-printing characters in there?

– Nick
Nov 13 '18 at 11:09













No just this text

– Ali Zia
Nov 13 '18 at 11:10





No just this text

– Ali Zia
Nov 13 '18 at 11:10













4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

– Utkanos
Nov 13 '18 at 11:11







4 = "JSON_ERROR_SYNTAX" - php.net/manual/en/function.json-last-error.php. Show us how you're setting $result.

– Utkanos
Nov 13 '18 at 11:11














3 Answers
3






active

oldest

votes


















3














I have solved this issue please check this below code



<?php
// Your code here!
$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
echo '<hr>';
curl_close($ch);

// This will remove unwanted characters.
// Check http://www.php.net/chr for details
for ($i = 0; $i <= 31; ++$i) {
$result = str_replace(chr($i), "", $result);
}
$result = str_replace(chr(127), "", $result);

// This is the most common part
// Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
// here we detect it and we remove it, basically it's the first 3 characters
if (0 === strpos(bin2hex($result), 'efbbbf')) {
$result = substr($result, 3);
}

$json_result = json_decode($result, true);

echo json_last_error_msg();
echo '<hr>';
print_r($json_result);

?>


I am sure it's work properly please check



Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function



Happy Programming



Thanks,
AS






share|improve this answer


























  • @Ali Zia : Have you checked my answer ?

    – Abhijit
    Nov 13 '18 at 12:28











  • would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

    – ADyson
    Nov 13 '18 at 12:42













  • @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

    – Abhijit
    Nov 13 '18 at 12:48








  • 1





    please add the explanation to the answer itself - thanks.

    – ADyson
    Nov 13 '18 at 12:49



















-1














Hi I found that on stackoverflow: here



<?php

function removeBOM($data) {
if (0 === strpos(bin2hex($data), 'efbbbf')) {
return substr($data, 3);
}
return $data;
}

$data = "&userId=";
$data_string = $data;
$url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
$result = removeBOM($result);
echo $result;

curl_close($ch);
$json_result = json_decode(trim($result), false);
echo json_last_error_msg();
//$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
print_r($json_result);
?>





share|improve this answer


























  • found what exactly? Can you explain your code please and how it solves the problem.

    – ADyson
    Nov 13 '18 at 11:38













  • Please also explain the code so that I can understand what removeBOM is doing

    – Ali Zia
    Nov 13 '18 at 11:39











  • jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

    – Alive to Die
    Nov 13 '18 at 11:57





















-1














just you need to add the trim before decoding your code.You will get the result as it is getting some extra data






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279669%2fjson-decode-giving-null-on-a-valid-json%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    I have solved this issue please check this below code



    <?php
    // Your code here!
    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo $result = curl_exec($ch);
    echo '<hr>';
    curl_close($ch);

    // This will remove unwanted characters.
    // Check http://www.php.net/chr for details
    for ($i = 0; $i <= 31; ++$i) {
    $result = str_replace(chr($i), "", $result);
    }
    $result = str_replace(chr(127), "", $result);

    // This is the most common part
    // Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
    // here we detect it and we remove it, basically it's the first 3 characters
    if (0 === strpos(bin2hex($result), 'efbbbf')) {
    $result = substr($result, 3);
    }

    $json_result = json_decode($result, true);

    echo json_last_error_msg();
    echo '<hr>';
    print_r($json_result);

    ?>


    I am sure it's work properly please check



    Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function



    Happy Programming



    Thanks,
    AS






    share|improve this answer


























    • @Ali Zia : Have you checked my answer ?

      – Abhijit
      Nov 13 '18 at 12:28











    • would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

      – ADyson
      Nov 13 '18 at 12:42













    • @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

      – Abhijit
      Nov 13 '18 at 12:48








    • 1





      please add the explanation to the answer itself - thanks.

      – ADyson
      Nov 13 '18 at 12:49
















    3














    I have solved this issue please check this below code



    <?php
    // Your code here!
    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo $result = curl_exec($ch);
    echo '<hr>';
    curl_close($ch);

    // This will remove unwanted characters.
    // Check http://www.php.net/chr for details
    for ($i = 0; $i <= 31; ++$i) {
    $result = str_replace(chr($i), "", $result);
    }
    $result = str_replace(chr(127), "", $result);

    // This is the most common part
    // Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
    // here we detect it and we remove it, basically it's the first 3 characters
    if (0 === strpos(bin2hex($result), 'efbbbf')) {
    $result = substr($result, 3);
    }

    $json_result = json_decode($result, true);

    echo json_last_error_msg();
    echo '<hr>';
    print_r($json_result);

    ?>


    I am sure it's work properly please check



    Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function



    Happy Programming



    Thanks,
    AS






    share|improve this answer


























    • @Ali Zia : Have you checked my answer ?

      – Abhijit
      Nov 13 '18 at 12:28











    • would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

      – ADyson
      Nov 13 '18 at 12:42













    • @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

      – Abhijit
      Nov 13 '18 at 12:48








    • 1





      please add the explanation to the answer itself - thanks.

      – ADyson
      Nov 13 '18 at 12:49














    3












    3








    3







    I have solved this issue please check this below code



    <?php
    // Your code here!
    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo $result = curl_exec($ch);
    echo '<hr>';
    curl_close($ch);

    // This will remove unwanted characters.
    // Check http://www.php.net/chr for details
    for ($i = 0; $i <= 31; ++$i) {
    $result = str_replace(chr($i), "", $result);
    }
    $result = str_replace(chr(127), "", $result);

    // This is the most common part
    // Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
    // here we detect it and we remove it, basically it's the first 3 characters
    if (0 === strpos(bin2hex($result), 'efbbbf')) {
    $result = substr($result, 3);
    }

    $json_result = json_decode($result, true);

    echo json_last_error_msg();
    echo '<hr>';
    print_r($json_result);

    ?>


    I am sure it's work properly please check



    Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function



    Happy Programming



    Thanks,
    AS






    share|improve this answer















    I have solved this issue please check this below code



    <?php
    // Your code here!
    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo $result = curl_exec($ch);
    echo '<hr>';
    curl_close($ch);

    // This will remove unwanted characters.
    // Check http://www.php.net/chr for details
    for ($i = 0; $i <= 31; ++$i) {
    $result = str_replace(chr($i), "", $result);
    }
    $result = str_replace(chr(127), "", $result);

    // This is the most common part
    // Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
    // here we detect it and we remove it, basically it's the first 3 characters
    if (0 === strpos(bin2hex($result), 'efbbbf')) {
    $result = substr($result, 3);
    }

    $json_result = json_decode($result, true);

    echo json_last_error_msg();
    echo '<hr>';
    print_r($json_result);

    ?>


    I am sure it's work properly please check



    Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function



    Happy Programming



    Thanks,
    AS







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 '18 at 12:52

























    answered Nov 13 '18 at 12:16









    AbhijitAbhijit

    1,002715




    1,002715













    • @Ali Zia : Have you checked my answer ?

      – Abhijit
      Nov 13 '18 at 12:28











    • would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

      – ADyson
      Nov 13 '18 at 12:42













    • @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

      – Abhijit
      Nov 13 '18 at 12:48








    • 1





      please add the explanation to the answer itself - thanks.

      – ADyson
      Nov 13 '18 at 12:49



















    • @Ali Zia : Have you checked my answer ?

      – Abhijit
      Nov 13 '18 at 12:28











    • would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

      – ADyson
      Nov 13 '18 at 12:42













    • @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

      – Abhijit
      Nov 13 '18 at 12:48








    • 1





      please add the explanation to the answer itself - thanks.

      – ADyson
      Nov 13 '18 at 12:49

















    @Ali Zia : Have you checked my answer ?

    – Abhijit
    Nov 13 '18 at 12:28





    @Ali Zia : Have you checked my answer ?

    – Abhijit
    Nov 13 '18 at 12:28













    would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

    – ADyson
    Nov 13 '18 at 12:42







    would you like to explain to us exactly what you've done in the code to solve it, in case it's not obvious what you have changed, and more importantly why you changed it.

    – ADyson
    Nov 13 '18 at 12:42















    @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

    – Abhijit
    Nov 13 '18 at 12:48







    @ADyson : Curl sent json response .it's display proper json but it's have unwanted characters. we have remove unwanted characters binary level.Then pass to json_decode function

    – Abhijit
    Nov 13 '18 at 12:48






    1




    1





    please add the explanation to the answer itself - thanks.

    – ADyson
    Nov 13 '18 at 12:49





    please add the explanation to the answer itself - thanks.

    – ADyson
    Nov 13 '18 at 12:49













    -1














    Hi I found that on stackoverflow: here



    <?php

    function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
    return substr($data, 3);
    }
    return $data;
    }

    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    $result = removeBOM($result);
    echo $result;

    curl_close($ch);
    $json_result = json_decode(trim($result), false);
    echo json_last_error_msg();
    //$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
    print_r($json_result);
    ?>





    share|improve this answer


























    • found what exactly? Can you explain your code please and how it solves the problem.

      – ADyson
      Nov 13 '18 at 11:38













    • Please also explain the code so that I can understand what removeBOM is doing

      – Ali Zia
      Nov 13 '18 at 11:39











    • jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

      – Alive to Die
      Nov 13 '18 at 11:57


















    -1














    Hi I found that on stackoverflow: here



    <?php

    function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
    return substr($data, 3);
    }
    return $data;
    }

    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    $result = removeBOM($result);
    echo $result;

    curl_close($ch);
    $json_result = json_decode(trim($result), false);
    echo json_last_error_msg();
    //$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
    print_r($json_result);
    ?>





    share|improve this answer


























    • found what exactly? Can you explain your code please and how it solves the problem.

      – ADyson
      Nov 13 '18 at 11:38













    • Please also explain the code so that I can understand what removeBOM is doing

      – Ali Zia
      Nov 13 '18 at 11:39











    • jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

      – Alive to Die
      Nov 13 '18 at 11:57
















    -1












    -1








    -1







    Hi I found that on stackoverflow: here



    <?php

    function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
    return substr($data, 3);
    }
    return $data;
    }

    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    $result = removeBOM($result);
    echo $result;

    curl_close($ch);
    $json_result = json_decode(trim($result), false);
    echo json_last_error_msg();
    //$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
    print_r($json_result);
    ?>





    share|improve this answer















    Hi I found that on stackoverflow: here



    <?php

    function removeBOM($data) {
    if (0 === strpos(bin2hex($data), 'efbbbf')) {
    return substr($data, 3);
    }
    return $data;
    }

    $data = "&userId=";
    $data_string = $data;
    $url = 'http://apptellect.cloudapp.net/binance/api/v1/get_user_assets/';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    $result = removeBOM($result);
    echo $result;

    curl_close($ch);
    $json_result = json_decode(trim($result), false);
    echo json_last_error_msg();
    //$json_result = json_decode( preg_replace('/[x00-x1Fx80-xFF]/', '', $result), true );
    print_r($json_result);
    ?>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 '18 at 12:03









    Alive to Die

    55.8k82869




    55.8k82869










    answered Nov 13 '18 at 11:35









    jawbonewalkjawbonewalk

    16218




    16218













    • found what exactly? Can you explain your code please and how it solves the problem.

      – ADyson
      Nov 13 '18 at 11:38













    • Please also explain the code so that I can understand what removeBOM is doing

      – Ali Zia
      Nov 13 '18 at 11:39











    • jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

      – Alive to Die
      Nov 13 '18 at 11:57





















    • found what exactly? Can you explain your code please and how it solves the problem.

      – ADyson
      Nov 13 '18 at 11:38













    • Please also explain the code so that I can understand what removeBOM is doing

      – Ali Zia
      Nov 13 '18 at 11:39











    • jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

      – Alive to Die
      Nov 13 '18 at 11:57



















    found what exactly? Can you explain your code please and how it solves the problem.

    – ADyson
    Nov 13 '18 at 11:38







    found what exactly? Can you explain your code please and how it solves the problem.

    – ADyson
    Nov 13 '18 at 11:38















    Please also explain the code so that I can understand what removeBOM is doing

    – Ali Zia
    Nov 13 '18 at 11:39





    Please also explain the code so that I can understand what removeBOM is doing

    – Ali Zia
    Nov 13 '18 at 11:39













    jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

    – Alive to Die
    Nov 13 '18 at 11:57







    jawbonewalk when you found a duplicate link then try to close the question with that link instead of re-answering the question with same code.

    – Alive to Die
    Nov 13 '18 at 11:57













    -1














    just you need to add the trim before decoding your code.You will get the result as it is getting some extra data






    share|improve this answer




























      -1














      just you need to add the trim before decoding your code.You will get the result as it is getting some extra data






      share|improve this answer


























        -1












        -1








        -1







        just you need to add the trim before decoding your code.You will get the result as it is getting some extra data






        share|improve this answer













        just you need to add the trim before decoding your code.You will get the result as it is getting some extra data







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 12:23









        akshika guptaakshika gupta

        11




        11






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279669%2fjson-decode-giving-null-on-a-valid-json%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation