<?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 character escaping function in classic ASP</title>
	<atom:link href="http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Tue, 10 May 2011 13:11:20 +0200</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Emtucifor</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comment-10297</link>
		<dc:creator>Emtucifor</dc:creator>
		<pubDate>Tue, 19 May 2009 23:42:09 +0000</pubDate>
		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32#comment-10297</guid>
		<description>And the second comment in the last If statement should be removed. It is a leftover after reordering the code to hit most likely conditions first in the loop.</description>
		<content:encoded><![CDATA[<p>And the second comment in the last If statement should be removed. It is a leftover after reordering the code to hit most likely conditions first in the loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emtucifor</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comment-10294</link>
		<dc:creator>Emtucifor</dc:creator>
		<pubDate>Tue, 19 May 2009 23:39:41 +0000</pubDate>
		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32#comment-10294</guid>
		<description>For want of a preview function, a p was lost :) ...

[asp]Function JSONEscape(json)
   Dim Pos
   Dim Char
   Dim Code
   JSONEscape = &quot;&quot;
	If IsNull(json) Then Exit Function
   For Pos = 1 To Len(json)
      Char = Mid(json, Pos, 1)
      Code = AscW(Char)
      If (Code &gt;= 32 And Code &lt;= 127) And Code  34 And Code  39 And Code  60 And Code  92 Then &#039;printable, plus skip &#039;&quot;\ and to avoid false HTML tags  0 Then
            JSONEscape = JSONEscape &amp; &quot;\&quot; &amp; VBA.Mid(&quot;bfnOrtv&#039;&quot;&quot;\&quot;, Code, 1)
         Else
            Code = AscW(Char)
            If (Code &gt;= 0 And Code &lt;= 255) Then &#039;escape nonprinting, high ascii, and &lt; characters (to avoid false HTML tags)&#039;
               JSONEscape = JSONEscape &amp; &quot;\x&quot; &amp; VBA.Right(&quot;0&quot; &amp; Hex(Code), 2)
            Else
               JSONEscape = JSONEscape &amp; &quot;\u&quot; &amp; VBA.Right(&quot;000&quot; &amp; Hex(Code), 4)
            End If
         End If
      End If
   Next
End Function[/asp]</description>
		<content:encoded><![CDATA[<p>For want of a preview function, a p was lost :) ...</p>
<div class="igBar"><span id="lasp-1"><a href="#" onclick="javascript:showCodeTxt('asp-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-1">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">Function</span> JSONEscape<span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#0000FF; font-weight:bold;">Dim</span> Pos</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#0000FF; font-weight:bold;">Dim</span> Char</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#0000FF; font-weight:bold;">Dim</span> Code</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;JSONEscape = <span style="color:#CC0000;">""</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">If</span> <span style="color:#990099; font-weight:bold;">IsNull</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">Then</span> <span style="color:#990099; font-weight:bold;">Exit</span> <span style="color:#0000FF; font-weight:bold;">Function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">For</span> Pos = <span style="color:#800000;color:#800000;">1</span> <span style="color:#990099; font-weight:bold;">To</span> <span style="color:#990099; font-weight:bold;">Len</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; Char = <span style="color:#990099; font-weight:bold;">Mid</span><span style="color:#006600; font-weight:bold;">&#40;</span>json, Pos, <span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; Code = AscW<span style="color:#006600; font-weight:bold;">&#40;</span>Char<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">If</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Code&amp;gt;= <span style="color:#800000;color:#800000;">32</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code &amp;lt;= <span style="color:#800000;color:#800000;">127</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code&nbsp; <span style="color:#800000;color:#800000;">34</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code&nbsp; <span style="color:#800000;color:#800000;">39</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code&nbsp; <span style="color:#800000;color:#800000;">60</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code&nbsp; <span style="color:#800000;color:#800000;">92</span> <span style="color:#990099; font-weight:bold;">Then</span> <span style="color:#008000;">'printable, plus skip '&quot;\ and to avoid false HTML tags&nbsp; 0 Then</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONEscape = JSONEscape &amp;amp; <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\"</span> &amp;amp; VBA.Mid("</span>bfnOrtv<span style="color:#008000;">'&quot;&quot;\&quot;, Code, 1)</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">Else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code = AscW<span style="color:#006600; font-weight:bold;">&#40;</span>Char<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">If</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Code&amp;gt;= <span style="color:#800000;color:#800000;">0</span> <span style="color:#0000FF; font-weight:bold;">And</span> Code &amp;lt;= <span style="color:#800000;color:#800000;">255</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">Then</span> <span style="color:#008000;">'escape nonprinting, high ascii, and &amp;lt;characters (to avoid false HTML tags)'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONEscape = JSONEscape &amp;amp; <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\x</span>"</span> &amp;amp; VBA.<span style="color:#990099; font-weight:bold;">Right</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"0"</span> &amp;amp; <span style="color:#990099; font-weight:bold;">Hex</span><span style="color:#006600; font-weight:bold;">&#40;</span>Code<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">Else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONEscape = JSONEscape &amp;amp; <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\u</span>"</span> &amp;amp; VBA.<span style="color:#990099; font-weight:bold;">Right</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"000"</span> &amp;amp; <span style="color:#990099; font-weight:bold;">Hex</span><span style="color:#006600; font-weight:bold;">&#40;</span>Code<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">End</span> <span style="color:#990099; font-weight:bold;">If</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">End</span> <span style="color:#990099; font-weight:bold;">If</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">End</span> <span style="color:#990099; font-weight:bold;">If</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">Next</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">End</span> <span style="color:#0000FF; font-weight:bold;">Function</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emtucifor</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comment-10293</link>
		<dc:creator>Emtucifor</dc:creator>
		<pubDate>Tue, 19 May 2009 23:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32#comment-10293</guid>
		<description>I rate this code: FLUNK.

Your code:
- Escapes characters unnecessarily (such as forward slash).
- Escapes using more characters than needed, making the JSON longer (using hex notation instead of simple backslash-escaping).
- Escapes every high Ascii character as \u00__ which is not only longer than \x__ but completely ignores the first byte of Unicode characters, making the result meaningless.
- Has goofy stuff like &quot;- &amp;hC2C0&quot; which is clearly an undefined operation to perform on Unicode between &amp;hC380 and &amp;hC3BF. Perhaps you&#039;re matching character sets to character sets, but this is something you&#039;re supposed to solve with fonts, not subtraction to turn one code into another. To make your preposterous claim &quot;This stuff has been tested and works for all characters so everything can be transfered with JSON now&quot; valid, you have to rip out this junk. I don&#039;t care how elaborate a character map you use, you&#039;ll still be altering characters, hardly the desire of most people who want to send Unicode characters through JSON from ASP.

Here is my version:

[asp]Function JSONEscape(json)
   Dim Pos
   Dim Char
   Dim Code
   JSONEscape = &quot;&quot;
	If IsNull(json) Then Exit Function
   For Pos = 1 To Len(json)
      Char = Mid(json, Pos, 1)
      Code = AscW(Char)
      If (Code &gt;= 32 And Code &lt;= 127) And Code  34 And Code  39 And Code  60 And Code  92 Then &#039;printable, plus skip &#039;&quot;\ and to avoid false HTML tags  0 Then
            JSONEscape = JSONEscape &amp; &quot;\&quot; &amp; VBA.Mid(&quot;bfnOrtv&#039;&quot;&quot;\&quot;, Code, 1)
         Else
            Code = AscW(Char)
            If (Code &gt;= 0 And Code &lt;= 255) Then &#039;escape nonprinting, high ascii, and &lt; characters (to avoid false HTML tags)&#039;
               JSONEscape = JSONEscape &amp; &quot;\x&quot; &amp; VBA.Right(&quot;0&quot; &amp; Hex(Code), 2)
            Else
               JSONEscape = JSONEscape &amp; &quot;\u&quot; &amp; VBA.Right(&quot;000&quot; &amp; Hex(Code), 4)
            End If
         End If
      End If
   Next
End Function[/as]</description>
		<content:encoded><![CDATA[<p>I rate this code: FLUNK.</p>
<p>Your code:<br />
- Escapes characters unnecessarily (such as forward slash).<br />
- Escapes using more characters than needed, making the JSON longer (using hex notation instead of simple backslash-escaping).<br />
- Escapes every high Ascii character as \u00__ which is not only longer than \x__ but completely ignores the first byte of Unicode characters, making the result meaningless.<br />
- Has goofy stuff like "- &amp;hC2C0" which is clearly an undefined operation to perform on Unicode between &amp;hC380 and &amp;hC3BF. Perhaps you're matching character sets to character sets, but this is something you're supposed to solve with fonts, not subtraction to turn one code into another. To make your preposterous claim "This stuff has been tested and works for all characters so everything can be transfered with JSON now" valid, you have to rip out this junk. I don't care how elaborate a character map you use, you'll still be altering characters, hardly the desire of most people who want to send Unicode characters through JSON from ASP.</p>
<p>Here is my version:</p>
<p>[asp]Function JSONEscape(json)<br />
   Dim Pos<br />
   Dim Char<br />
   Dim Code<br />
   JSONEscape = ""<br />
	If IsNull(json) Then Exit Function<br />
   For Pos = 1 To Len(json)<br />
      Char = Mid(json, Pos, 1)<br />
      Code = AscW(Char)<br />
      If (Code &gt;= 32 And Code &lt;= 127) And Code  34 And Code  39 And Code  60 And Code  92 Then 'printable, plus skip '"\ and to avoid false HTML tags  0 Then<br />
            JSONEscape = JSONEscape &amp; "\" &amp; VBA.Mid("bfnOrtv'""\", Code, 1)<br />
         Else<br />
            Code = AscW(Char)<br />
            If (Code &gt;= 0 And Code &lt;= 255) Then 'escape nonprinting, high ascii, and &lt; characters (to avoid false HTML tags)'<br />
               JSONEscape = JSONEscape &amp; "\x" &amp; VBA.Right("0" &amp; Hex(Code), 2)<br />
            Else<br />
               JSONEscape = JSONEscape &amp; "\u" &amp; VBA.Right("000" &amp; Hex(Code), 4)<br />
            End If<br />
         End If<br />
      End If<br />
   Next<br />
End Function[/as]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comment-9686</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Fri, 27 Mar 2009 16:07:19 +0000</pubDate>
		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32#comment-9686</guid>
		<description>Hi Michal,

I&#039;m having a problem converting the string back to special characters. When I get data from JSON and the strings are escaped, and I need to put that data into a form field the \uuxx numbers are still there instead of the special characters. Do you have, or know of any function that reverses this process?

Erik</description>
		<content:encoded><![CDATA[<p>Hi Michal,</p>
<p>I'm having a problem converting the string back to special characters. When I get data from JSON and the strings are escaped, and I need to put that data into a form field the \uuxx numbers are still there instead of the special characters. Do you have, or know of any function that reverses this process?</p>
<p>Erik</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: amol</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comment-9554</link>
		<dc:creator>amol</dc:creator>
		<pubDate>Fri, 31 Oct 2008 11:10:34 +0000</pubDate>
		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32#comment-9554</guid>
		<description>Thanks a ton! I was going crazy coz wasn&#039;t finding one suitable solution for ASP. Thanks again!</description>
		<content:encoded><![CDATA[<p>Thanks a ton! I was going crazy coz wasn't finding one suitable solution for ASP. Thanks again!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

