Web Connection
Minimum Working Temperature (°F): "-20"
Gravatar is a globally recognized avatar based on your email address. Minimum Working Temperature (°F): "-20"
  Michael B
  All
  Nov 8, 2017 @ 09:21am

Rick,

Checkout the text in the subject. I receive this content from a popular web service my app uses. I discovered that this text is crashing the JSON parser - E.g. loSerializer.DeserializeJson(m.lc).

In the framework we have: lcName = CHRTRAN(lcName," `~!@#$%^&*()-+={}[]|/?.,<>:;'" + ["],"")

Maybe you can add the ° in here?

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Rick Strahl
  Michael B
  Nov 8, 2017 @ 11:40am

Uh no 😃

If you have JSON that includes invalid characters that are not supported by FoxPro it'll crash. Since the serializer creates properties from the JSON properties and FoxPro can't use 'dynamic' string based names like JavaScript it's going to break. This will happen with any variable that includes extended characters that can't be expressed as FoxPro values.

Garbage in - Garbage out stands pretty much in this scenario.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Michael B
  Michael B
  Nov 8, 2017 @ 11:52am

I did predict your answer to one of my dev's just seconds before reading it (lol). However, I would think that if your comment is ubiquitous that a site like jsonlint or the equivalent should fail the formatting and validation, no?

(holding my breath until you reply...)

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Rick Strahl
  Michael B
  Nov 8, 2017 @ 12:23pm

For JavaScript you can use:

var obj = {};
obj["Really Hot 100° Weather"] = "Hot Potato";
var text  =  obj["Really Hot 100° Weather"];  // Hot Potato

However JavaScript also doesn't support that same var name as an attach object property, same as FoxPro.

Point is - if people do stupid shit in JSON, it won't translate into Foxpro. I suppose we could strip just about everything but numbers, text and certain dashes, so as to be legal, but then you run into other problems like duplication very quickly.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Michael B
  Rick Strahl
  Nov 8, 2017 @ 02:23pm

My thought was that since the framework already has this: lcName = CHRTRAN(lcName," `~!@#$%^&*()-+={}[]|/?.,<>:;'" + ["],"") - You have set the stage for eliminating non-alpha characters.

  • or -

Wouldn't we want to display - \u00b0

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Rick Strahl
  Michael B
  Nov 8, 2017 @ 03:18pm

Ok fine. Challenge accepted.

As far as I know FoxPro supports varnames to only have alpha numeric digits and _. Everything else is effectively invalid.


Add Property to wwJsonSerializer:

VarNameCharacterFilter = ""

In Init:

lcCharFilter = ""
FOR lnX = 1 TO 255
	IF (lnX >= 65 AND lnX <= 90) OR ;
	   (lnX >= 97 AND lnX <= 122) OR ;
	   (lnX >=48 AND lnX <=57) OR ;
	   lnX = 95 
	   loop
	ENDIF
	lcCharFilter = lcCharFilter + CHR(lnX)
ENDFOR

THIS.VarNameCharacterFilter = lcCharFilter

In ParseObject:

lcName = CHRTRAN(lcName,this.VarNameCharacterFilter,"")

This then works:

DO wwJsonSerializer  && Load Libs

lcJson = [{ "100°Weather_zZAa09": "It's hot" }]

o = CREATEOBJECT("wwJsonSerializer")
loResult = o.DeSerializeJson(lcJson)

? loResult._100Weather_zZAa09

Note FoxPro doesn't allow vars that start with a digit so the serializer prefixes with _.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Minimum Working Temperature (°F): "-20"
  Michael B
  Rick Strahl
  Nov 8, 2017 @ 03:49pm

Ha! You are awesome. By any chance will your slick lil funtion make its way into the framework for 6.18 ?

© 1996-2024