Php parses the json string from HTMLpost. how can this problem be solved?

Source: Internet
Author: User
Php parses the json string from HTMLpost. this post is finally edited by asia_deng from 2014-07-0715: 48: 48. I converted a json object into a json string in js, put it in an implicit input and submit it to php. this is the HTML part. & lt; input & nbsp; typehidden & nbsp php parses the json string from HTML post.

This post was last edited by asia_deng at 15:48:48, January 7 ,.

In js, I convert a json object into a json string and put it in an implicit input to submit it to php.
This is the HTML part.




The string obtained in php is:

[{\\"table\\":\\"a\\",\\"field\\":\\"value\\",\\"max\\":60,\\"min\\":null}]

String Processing

$ Json_string = $ _ POST ['json'];
$ Json = htmlspecialchars_decode ($ json_string );
Print_r (json_decode ($ json); // The result is null.


Change

$ Json = stripslashes (htmlspecialchars_decode ($ json_string ));
Print_r (json_decode ($ json); // The result is still null.


Change it.

$ Json = stripslashes (htmlspecialchars_decode ($ json_string )));
Print_r (json_decode ($ json); // well, the result is still empty.




------ Solution --------------------

This post was last edited by xuzuning at 15:57:51 on

It's really hard for you to do so complicated coding.
$s = '[{\\"table\\":\\"a\\",\\"field\\":\\"value\\",\\"max\\":60,\\"min\\":null}]';

$s = html_entity_decode($s);
$s = stripslashes($s);

print_r(json_decode($s, 1));
Array
(
[0] => Array
(
[table] => a
[field] => value
[max] => 60
[min] =>
)

)


------ Solution --------------------
$str='[{\\"table\\":\\"a\\",\\"field\\":\\"value\\",\\"max\\":60,\\"min\\":null}]';
$new=htmlspecialchars_decode($str);

$new=str_replace('\\','',$new);

$new1=json_decode($new,true);
echo "
";
print_r($new1);
echo "
";

Array
(
[0] => Array
(
[Table] =>
[Field] => value
[Max] => 60
[Min] =>
)

)
------ Solution --------------------
Echo base64_encode ($ _ POST ['json']);
Post result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.