Data having commas creating problem in json
I am developing a web applications where users are allowed to enter some text. To cre开发者_Python百科ate profile, I am using the text entered by users which is saved in database. Problem is, if the data entered by user contains a comma, it is spoiling my page as a json string can't contain a comma. Is there any encoding function in php for supporting commas in json.
Note: Am using zend framework's zend encoding function to encode json.
Solved: I got the solution of this problem, json encoding function of zend framework have some issues with encoding decimal data and comma and that was the reason it was creating problem. I used php's own json encode function.
Did you try json_encode ?
Works well for me:
<?php
$str = "my string.";
$json_str = json_encode($str);
echo $json_str . "\n";
Gives:
"my string."
Yes it can use any character.
$json = json_encode($your_array_or_string);
I'd say that as long as you encapsulate your data with either '
or "
, it won't parse the ,
as an actual separator. Use json_encode()
as @Patrik MARIE
stated above, and you won't be in the need of manually quoting everything!
精彩评论