Fix garbled message text: Difference between revisions

Jump to navigation Jump to search
m
Line 75: Line 75:
* [https://www.w3schools.com/js/js_json_parse.asp JSON.parse()] or [http://api.jquery.com/jquery.parsejson/ jQuery.parseJSON() | jQuery API Documentation]
* [https://www.w3schools.com/js/js_json_parse.asp JSON.parse()] or [http://api.jquery.com/jquery.parsejson/ jQuery.parseJSON() | jQuery API Documentation]


== List of the garbled text and possible cause ==
== List of the (look like but not) garbled text and possible cause ==
<table border="1" style="width: 100%; table-layout: fixed;" class="wikitable sortable">
<table border="1" style="width: 100%; table-layout: fixed;" class="wikitable sortable">
<tr>
<tr>
Line 90: Line 90:
</tr>
</tr>
<tr>
<tr>
<td>Downloaded Json or JavaScript file which its content contains {{kbd | key=<nowiki>\u</nowiki>}} or {{kbd | key=<nowiki>\U</nowiki>}} symbols</td>
<td>String start from {{kbd | key=<nowiki>\u</nowiki>}}, {{kbd | key=<nowiki>\U</nowiki>}} or {{kbd | key=<nowiki>U+</nowiki>}} symbols</td>
<td style="word-wrap: break-word;">{{kbd | key=<nowiki>\u8c61</nowiki>}} or {{kbd | key=<nowiki>\U0001f418</nowiki>}}</td>
<td style="word-wrap: break-word;">{{kbd | key=<nowiki>\u8c61</nowiki>}}, {{kbd | key=<nowiki>\U0001f418</nowiki>}} or {{kbd | key=<nowiki>U+1F418</nowiki>}}</td>
<td>(1) 16-bit or 32-bit hex value (2) "JSON representation of the supplied value"<ref>[http://php.net/manual/en/function.json-encode.php PHP: json_encode - Manual]</ref><ref>[http://www.faqs.org/rfcs/rfc7159.html RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format]</ref></td>
<td>"Unicode code point is referred to by writing "U+" followed by its hexadecimal number.<ref>[https://en.wikipedia.org/wiki/Unicode Unicode - Wikipedia]</ref>" (1) 16-bit or 32-bit hex value (2) "JSON representation of the supplied value"<ref>[http://php.net/manual/en/function.json-encode.php PHP: json_encode - Manual]</ref><ref>[http://www.faqs.org/rfcs/rfc7159.html RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format]</ref></td>
<td>JSON decode ↔ JSON eocode</td>
<td>JSON decode ↔ JSON eocode</td>
</tr>
</tr>
Line 112: Line 112:
Using PHP. Type is string
Using PHP. Type is string
<pre>
<pre>
$encoded = json_encode("象");
$encoded = <<<EOT
echo "encoded string: " . $encoded . PHP_EOL; // print "\u8c61"
 
"\u8c61"
 
EOT;
echo "decoded string: " . json_decode($encoded, true) . PHP_EOL; // print 象
echo "decoded string: " . json_decode($encoded, true) . PHP_EOL; // print 象
echo "encoded string: " . json_encode("象") . PHP_EOL; // print "\u8c61"
$encoded = <<<EOT
"\ud83d\udc18"


$encoded = json_encode("🐘");
EOT;
echo "encoded string: " . $encoded . PHP_EOL; // print "\ud83d\udc18"
echo "decoded string: " . json_decode($encoded, true) . PHP_EOL; // print 🐘
echo "decoded string: " . json_decode($encoded, true) . PHP_EOL; // print 🐘
echo "encoded string: " . json_encode("🐘") . PHP_EOL; // print "\ud83d\udc18"
</pre>
</pre>


Navigation menu