App json exception

  1. 2 weeks ago

    Richard A

    May 15 Pre-Release Testers, Xojo Pro

    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<WebResponse>
    WebSession._HandleEvent%%o<WebSession>so<_HTTPServer.HTTPRequestContext>
    WebSession._HandleRequest%i8%o<WebSession>so<_HTTPServer.HTTPRequestContext>
    WebApplication._HandleHTTPRequest%%o<WebApplication>o<_HTTPServer.HTTPRequestContext>
    _CGIGateway.GatewayRequestThread.Event_Run%%o<_CGIGateway.GatewayRequestThread>

  2. Greg O

    May 15 Xojo Inc Somewhere near Raleigh, NC

    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.

  3. Richard A

    May 15 Pre-Release Testers, Xojo Pro

    At the top of my open I have: SQLExecute("Set NameS 'utf8'")

    Doesn't that do it.

  4. Richard A

    May 15 Pre-Release Testers, Xojo Pro

    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:

    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
    '
  5. Greg O

    May 15 Xojo Inc Somewhere near Raleigh, NC

    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:

    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
  6. Øjvind S

    May 16 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    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 :-)

  7. Richard A

    May 16 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    @Greg OLone

    lsCompany is clean "A.O. Smith Corp."

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

  8. Richard A

    May 16 Pre-Release Testers, Xojo Pro

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

    So what could the problenmbe with one field?

  9. Richard A

    May 16 Pre-Release Testers, Xojo Pro

    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.

  10. Richard A

    May 16 Pre-Release Testers, Xojo Pro

    @Greg OLone

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

  11. Richard A

    May 16 Pre-Release Testers, Xojo Pro

    Solved in first thread.

or Sign Up to reply!