开发者

getting json data from php server with """

My iphone app getting json data from php server.

2 basic questions, just 开发者_运维问答to be sure :

1-In some of the json data fields, i see """, is this how json send Quotes, and I need to clean it in the iphone app ? or there is elegant and clean way to skip this thing ?

2-The data is in UTF-8, I notice that if there is array in array, the UTF-8 is not display in the right way, and it's show codes. Is this a bug in the JSON library ? or there is somthing to check with the server side ?

thanks in advance.


What's probably happening is that the quote is encoded ", and then the ampersand is getting encoded ". It's happened to myself a few time when doing a find and replace on my JSON/XML files. Just go through and change them back to ".

If you're fetching them from another API or source where you can't edit their format, just use

html_entity_decode($json->data);

around anything you're printing to the page.


A literal quote anywhere in a JSON string should be \". """ would be invalid JSON and a syntax error. Which "server" is producing this JSON text? The iphone, or PHP's json_encode()?


is this how json send Quotes

No. " is an HTML or XML entity. A quote in JSON would be "\""

I notice that if there is array in array, the UTF-8 is not display in the right way, and it's show codes. Is this a bug in the JSON library ?

It might be a bug in the encoder. It might be a bug in the decoder. It might be a bug in how you are using one of them.

We can't tell without knowing more about what the input and output looks like.


" is a HTML entity, a way of representing characters that might otherwise be interpreted as HTML code by the browser.

PHP 5.2/5.3 (can't speak for others) shouldn't touch the html entities, so ensure that you're not running html_entities(...) on your json_encode string. Highly doubt the bug is in the encoder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜