<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: json decode fails on non utf-8</title>
	<atom:link href="http://www.overflow.biz/blog/lang/en-us/2010/03/16/json-decode-fails-on-non-utf-8/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overflow.biz/blog/lang/en-us/2010/03/16/json-decode-fails-on-non-utf-8?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=json-decode-fails-on-non-utf-8</link>
	<description>Coding and Internet Randomness</description>
	<lastBuildDate>Sun, 01 Apr 2012 05:34:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: z3n</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/03/16/json-decode-fails-on-non-utf-8/comment-page-1/#comment-244</link>
		<dc:creator>z3n</dc:creator>
		<pubDate>Thu, 25 Mar 2010 04:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=331#comment-244</guid>
		<description>Hi,

for ISO-8859-1 i use iconv function like this:

$x=json_decode( // (3) decode json
	iconv( // (2) convert accents 
		&#039;ISO-8859-1&#039;,&#039;UTF-8&#039;,base64_decode($_POST[&#039;d&#039;]) // (1) decode base64
	)
,true);

where $_POST[&#039;d&#039;] is the value sent. Since you&#039;re dealing with multibyte chars you will need the mb_convert_encoding($x,&quot;ISO-8859-1&quot;,&quot;UTF-8&quot;); instead of the iconv. Note that your charset isen&#039;t ISO-8859-1, search the charset code page to know which one is the right one.

- z3n</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>for ISO-8859-1 i use iconv function like this:</p>
<p>$x=json_decode( // (3) decode json<br />
	iconv( // (2) convert accents<br />
		&#8216;ISO-8859-1&#8242;,&#8217;UTF-8&#8242;,base64_decode($_POST['d']) // (1) decode base64<br />
	)<br />
,true);</p>
<p>where $_POST['d'] is the value sent. Since you&#8217;re dealing with multibyte chars you will need the mb_convert_encoding($x,&#8221;ISO-8859-1&#8243;,&#8221;UTF-8&#8243;); instead of the iconv. Note that your charset isen&#8217;t ISO-8859-1, search the charset code page to know which one is the right one.</p>
<p>- z3n</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MC</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/03/16/json-decode-fails-on-non-utf-8/comment-page-1/#comment-243</link>
		<dc:creator>MC</dc:creator>
		<pubDate>Thu, 25 Mar 2010 01:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=331#comment-243</guid>
		<description>I try to convert an array into json by using json_encode.

The code is as following:

// code is coming --------------------------

$marker1 = array(&#039;name&#039;=&gt;&#039;name1&#039;, &#039;id&#039; =&gt; 1);
$marker2 = array(&#039;name&#039;=&gt;&#039;中文&#039;, &#039;id&#039; =&gt; 2 );

// prepare the array
$markers = array(&#039;markers&#039;=&gt;array($marker1,$marker2));

// convert to json
$output = json_encode($markers);

// set header for json document
if(!headers_sent()) 
{
	header(&#039;Content-Type: application/json; charset=utf-8&#039;, true,200); 
}

print($output);


As a result, 
all is perfect except the chinese characters.
It becomes sth like 

\u00e4\u00b8\u00ad

What should I do to make it correct?

Regards,
MC</description>
		<content:encoded><![CDATA[<p>I try to convert an array into json by using json_encode.</p>
<p>The code is as following:</p>
<p>// code is coming &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>$marker1 = array(&#8216;name&#8217;=&gt;&#8217;name1&#8242;, &#8216;id&#8217; =&gt; 1);<br />
$marker2 = array(&#8216;name&#8217;=&gt;&#8217;中文&#8217;, &#8216;id&#8217; =&gt; 2 );</p>
<p>// prepare the array<br />
$markers = array(&#8216;markers&#8217;=&gt;array($marker1,$marker2));</p>
<p>// convert to json<br />
$output = json_encode($markers);</p>
<p>// set header for json document<br />
if(!headers_sent())<br />
{<br />
	header(&#8216;Content-Type: application/json; charset=utf-8&#8242;, true,200);<br />
}</p>
<p>print($output);</p>
<p>As a result,<br />
all is perfect except the chinese characters.<br />
It becomes sth like </p>
<p>\u00e4\u00b8\u00ad</p>
<p>What should I do to make it correct?</p>
<p>Regards,<br />
MC</p>
]]></content:encoded>
	</item>
</channel>
</rss>

