How can I prevent SerializeJSON from changing Yes/No/True/False strings to boolean?

后端 未结 6 605
失恋的感觉
失恋的感觉 2020-12-20 12:19

I have a data struct being stored in JSON format, converted using the serializeJSON function. The problem I am running into is that strings that can be boolean in CF such as

6条回答
  •  情深已故
    2020-12-20 12:51

    it's hacky, but if you conditionally output yes and no as "_yes_" and "_no_" (using a switch statement and then after serialising the JSON to a string, do a search and replace, it works.

    raw_json=serializeJSON(object);
    raw_json=ReplaceNoCase(raw_json,':"_Yes_"',':"Yes"',"ALL"); 
    raw_json=ReplaceNoCase(raw_json,':"_No_"',':"No"',"ALL");
    

    at least CF is consistantly frustrating with this, true & false get converted to yes no when you round trip the data

提交回复
热议问题