Jump to content

PHP json_decode not decoding


csplrj

Recommended Posts

Below is the code I have written for php json decoding.

Can't understand the reason

 

Thanks in advance

 

CSJakharia

 

 

PHP File

<?
$pages=$_POST['pages'];
if($pages!=null)
{
	$pages1=json_decode($pages);
	//echo((json_encode(array('a'=>1,'b'=>2))));
	echo($pages);
	var_dump($pages1);
	echo PHP_EOL;
	//echo($pages1);
	echo(' JSONERROR='.json_last_error());
}
?>
<form method="post" id="addPage">
<input type="hidden" value='[{"id":0},{"id":64, "websiteId":14, "pageName":"Home", "parentPageId":0, "pageTypeId":1, "orderNo":1, "pages":[]},{"id":65, "websiteId":14, "pageName":"a", "parentPageId":0, "pageTypeId":1, "orderNo":2, "pages":[{"id":66, "websiteId":14, "pageName":"b", "parentPageId":65, "pageTypeId":1, "orderNo":3, "pages":[]]},{"id":66, "websiteId":14, "pageName":"b", "parentPageId":65, "pageTypeId":1, "orderNo":3, "pages":[]},{"id":67, "websiteId":14, "pageName":"c", "parentPageId":0, "pageTypeId":1, "orderNo":4, "pages":[]}]' id="pages" name="pages"/>
<input type="hidden" value='[{"id":0},{"id":64, "websiteId":14, "pageName":"Home", "parentPageId":0, "pageTypeId":1, "orderNo":1, "pages":[]}]' id="pages" name="pages1"/>
<input type=submit>
</form>

 

 

But this output comes

NULL JSONERROR=2

 

Link to comment
Share on other sites

Below is the output for $pages

 

[{"id":0},{"id":64, "websiteId":14, "pageName":"Home", "parentPageId":0, "pageTypeId":1, "orderNo":1, "pages":[]},{"id":65, "websiteId":14, "pageName":"a", "parentPageId":0, "pageTypeId":1, "orderNo":2, "pages":[{"id":66, "websiteId":14, "pageName":"b", "parentPageId":65, "pageTypeId":1, "orderNo":3, "pages":[]]},{"id":66, "websiteId":14, "pageName":"b", "parentPageId":65, "pageTypeId":1, "orderNo":3, "pages":[]},{"id":67, "websiteId":14, "pageName":"c", "parentPageId":0, "pageTypeId":1, "orderNo":4, "pages":[]}]

Link to comment
Share on other sites

Thanks for the link given as it helped me in identifying the issue

 

I changed the json string and then When I try it does not works in PHP Version 5.2.4 but it works on PHP Version 5.3.1.

I have my shared hosting on PHP Version 5.2.4. How to do the same

 

<?
$pages=$_POST['pages'];
if($pages!=null)
{
	$pages1=json_decode($pages);
	var_dump($pages1);
}
?>
<form method="post" id="addPage">
<input type="hidden" value='[{"parentPageId":0, "id":0},{"parentPageId":0, "id":68},{"parentPageId":0, "id":69},{"parentPageId":69, "id":70},{"parentPageId":0, "id":71}]' id="pages" name="pages"/>
<input type=submit>
</form>

 

Thanks in advance

 

CSJakharia

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.