Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: JSON Special Characters?

$
0
0
Re: JSON Special Characters?
Web Connection 5.0
Re: JSON Special Characters?
Nov. 12, 2012
03:45 pm
3N50XSB3CShow this entire thread in new window
Gratar Image based on email address
From:Rick Strahl
To:Todd Landrum

<sigh>

Yes I can duplicate this unfortunately and I don't have a quick fix for it.

The problem is the mismatched braces in the RTF content - when searching for object strings the parser does brace matching by counting braces and it fails. Braces work but not if they're mismatched. Sadly the same problem exists with ] brackets.

I'll take a look and see if I can find a solution for this, but it's a big problem due to the fact that we can't parse the JSON one character at a time (too slow in VFP), so using patterns instead. But there are lots of pitfalls with this - nesting being the most difficult one to deal with.

+++ Rick ---



That worked for me as well, but when you do it via a cursor it fails during the Deserialize with a Function argument, type, count or count is invalid. I'm doing this:

CLEARDO wwJsonSerializerCREATETABLE Test FREE (SomeText M)TEXTTO lcText NOSHOW {\rtf1\ansi\deff0\deflang1033{\fonttbl{\f0\froman\fprq2 Arial;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\i\f0\fs20 Aid\i0 \par \cf0\fs18 \par }ENDTEXTSELECT testAPPENDBLANKreplace SomeText WITH lcText loJson = CREATEOBJECT("wwJsonSerializer") lcJson = loJson.Serialize("cursor:Test") loDeserialized = loJson.Deserialize(lcJson) loRow = loDeserialized.Rows.Item(1) ?loRow.SomeText == Test.SomeText

The code peels off the Rows part correctly, but when it attempts to deal with the text is when the error occurs. It looks like the wwRegEx.Match function is failing to find a match, so you end up with a .f. being returned when it should be finding some text.

It's the "{" and the "}" in the lctext that is a problem. If your remove those, then it works:
<code="vfp">
TEXT TO lcText NOSHOW
{\rtf1\ansi\deff0\deflang1033{\fonttbl{\f0\froman\fprq2 Arial;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\i\f0\fs20 Aid\i0
\par \cf0\fs18
\par }
ENDTEXT
lcText = STRTRAN(lcText, "{", "QQQ")
lcText = STRTRAN(lcText, "}", "QQQ")


This should work.

I tried this:

CLEARDO wwJsonSerializerTEXTTO lcText NOSHOW {\rtf1\ansi\deff0\deflang1033{\fonttbl{\f0\froman\fprq2 Arial;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\i\f0\fs20 Aid\i0 blah blah blah \ul blah\ul (blah blah). \par \cf0\fs18 \par }ENDTEXT ? lcText ? ? loJson = CREATEOBJECT("wwJsonSerializer") lcJson = loJson.Serialize(lcText) ? lcJson ? ? lcDeSerialized = loJson.Deserialize(lcJson) ? lcDeserialized ? lcText == lcDeserialized

and it two-way serializes/deserializes properly with the result string equaling the original value.

+++ Rick ---


I have a memo field with rich text that I'm doing a JSON serialize with. When I deserialize that, the field is just a .t.. Other fields are working fine, other memo fields work fine, it's just the rich text data. Does JSON have some special characters that might would mess things up? The data looks something like this:

{\rtf1\ansi\deff0\deflang1033{\fonttbl{\f0\froman\fprq2 Arial;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\i\f0\fs20 Aid\i0 blah blah blah \ul blah\ul (blah blah).
\par \cf0\fs18
\par }





Rick Strahl
West Wind Technologies


from Maui, Hawaii

Making waves on the Web


Viewing all articles
Browse latest Browse all 10393