App json exception

Hi,

Have a web app that displays a list box that gets populated from MySql. I’m getting this in the exception and am not sure what it is referring to as I’m not doing anything with Json.

Unhandled RuntimeException
Message: Encountered invalid character.

Stack:
RuntimeRaiseException
GenerateJSON
Xojo.Data.GenerateJSON%y%x <------------------------------------------------------------------------------What is this referring to?
WebResponse._Render%s%o
WebSession._HandleEvent%%oso<_HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i8%oso<_HTTPServer.HTTPRequestContext>
WebApplication._HandleHTTPRequest%%oo<_HTTPServer.HTTPRequestContext>
_CGIGateway.GatewayRequestThread.Event_Run%%o<_CGIGateway.GatewayRequestThread>

We are though. Data is sent to the browser as JSON and that implies UTF8. Check to make sure all of the text you’re putting into the listbox has an Encoding because data coming out of a database often does not.

At the top of my open I have: SQLExecute(“Set NameS ‘utf8’”)

Doesn’t that do it.

I just changed the statement to: self.SQLExecute(“Set Names ‘utf8_general_ci’”)

That got rid of the exception, but the listbox doesn’t get populates. I output one of the MySql fields to a local log with every iteration of the while loop. The log shows it went through the look, just didn’t populate the listbox.

Here’s the while loop:

[code]While not rs.eof

'System.DebugLog
App.WriteLog(rs.Field(“Company Name”).StringValue)

if lsCompany <> rs.Field(“Company Name”).StringValue then
lbFirst = True
lstProviders.AddRow rs.Field(“Company Name”).StringValue
lsCompany = rs.Field(“Company Name”).StringValue
end
lstProviders.AddRow( " -----", rs.Field(“Title”).StringValue, rs.Field(“Contact Person”).StringValue, rs.Field(“Email”).StringValue)
rs.MoveNext

wend
'[/code]

Set a breakpoint on the line that assigns lsCompany. If you inspect it, I suspect the encoding will still be Nil. If so, you’ll have to call DefineEncoding on that.

I typically use a String extension method:

[code]function UTF8(extends s as String) as String
If s.encoding = Encodings.UTF8 then
Return s
End if

If s.Encoding is Nil then
Return DefineEncoding(s, Encodings.UTF8)
End if

Return ConvertEncoding(s, Encodings.UTF8)
End Function[/code]

Maybe its related to:

https://forum.xojo.com/47396-how-to-replace-unicode-line-separator-u-2028-in-a-string/p1#p384795

As far as I remember I got error messages like the one you get.

Just a wild guess :slight_smile:

@Greg O’Lone

lsCompany is clean “A.O. Smith Corp.”

The Extends didn’t make a difference. Still nothing makes it to the listbox.

Found something, If I remove the field Title it works.

So what could the problenmbe with one field?

The Charcter Set for the field is utf8

and the collation is utf8_general_ci

I tried Changing it to text, changing length from 250 to 200.

No change in behavior.

@Greg O’Lone

I tried create table Test1 as Select * from system_manuceu and used the test1 table with same result.

Solved in first thread.