I'm sending a JSON encoded response to the request coming from iPhone. In few of the values some HTML entities are present. I tried using stripslashes()
and html_entity_decode()
on such values. In browser I'm able to get the proper JSON response i.e. without these HTML entities but when the same response is seen on iPhone or iPhone simulator the HTML entities displayed again.
How should I resolve this issue? Can someone please help?
If you wan I can provide you the necessary code.
Thanks.
What about using http://php.net/manual/en/function.strip-tags.php?
This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given str
in PHP
<?php
header('Content-Type: application/json');
echo json_encode(array('test' => html_entity_decode("Hello – World", ENT_COMPAT, 'UTF-8')));
Output:
{"test":"Hello \u2013 World"}
in JS
:
var o = jQuery.parseJSON('{"test":"Hello \u2013 World"}');
alert( o.test );
Output:
Hello – World
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With