Jump to content

Custom pages and json_decode


tomdchi

Recommended Posts

Is WHMCS doing something to php's json_decode function?

 

I have a custom client page where a json string is being posted from a form. I can echo out the post var before I call json_decode and it shows OK. After decode I print_r the output nothing is returned. Very strange.

Also, encoding is set to utf-8.

 

When I echo the json post var it outputs OK:

 

<?php
define("CLIENTAREA", true);
define("FORCESSL",true);
require("init.php");
$ca = new WHMCS_ClientArea();
$ca->setPageTitle("SureTax JSON Validator");
$ca->addToBreadCrumb('index.php', $whmcs->get_lang('globalsystemname'));
$ca->addToBreadCrumb('json_validator.php', 'SureTax JSON Validator');
$ca->initPage();
if (isset($_POST['json']))
{
   $json = $_POST['json'];
   echo $json;
   exit;
   $decoded = json_decode($json, true);
   print_r($decoded);

   $ca->assign('validate', validate_json($json));
}

 

Output:

{"ClientNumber":"000000002","BusinessUnit":"RPS","DataYear":"2013","DataMonth":"04","TotalRevenue":"32.00"}

 

Now when I try to run it through json_decode and print_r it outputs nothing.

 

if (isset($_POST['json']))
{
   $json = $_POST['json'];
   $decoded = json_decode($json, true);
   print_r($decoded);
   exit;
   $ca->assign('validate', validate_json($json));
}

 

Just to make sure that the json_decode function works I coded in the json string and the output was as expected.

 

if (isset($_POST['json']))
{
   $json = '{"ClientNumber":"000000002","BusinessUnit":"RPS","DataYear":"2013","DataMonth":"04","TotalRevenue":"32.00"}';
   $decoded = json_decode($json, true);
   print_r($decoded);
   exit;
   $ca->assign('validate', validate_json($json));
}

 

Output:

Array ( [ClientNumber] => 000000002 [businessUnit] => RPS [DataYear] => 2013 [DataMonth] => 04 [TotalRevenue] => 32.00 ) 

 

Anyone have any idea why it is doing this?

Edited by tomdchi
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated