Submitted by Jim Cooper on Wed, 04/18/2012 - 00:00
Forums

Hi Niels,

Can you please explain “everything” this procedure is doing:

encodeJsonStr(FirstName) 

Regards,

Jim

Niels Liisberg

Wed, 04/18/2012 - 00:00

Hi Jim;

You need to encode chars that otherwise will break the JSON structure: Lets say your "ItemText" variable contains: Tubes 15" long and 2" wide

If you place that values in JSON – then the parser will fail:

Var myObj = {
       "ItemText": "Tubes 15" long and 2" wide"
};

This is invalid since the parser thinks that the string ends just after "Tubes 15" and the rest: long and 2" wide" is totally garbage.

 

Now if you use encodeJsonStr on Tubes 15" long and 2" wide Then it will contain:

Var myObj = {
       "ItemText": "Tubes 15\" long and 2\" wide"
};

Now the string is valid for the JSON parser.

Also the \ will be encoded as \\

Best regards,

Niels Liisberg