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

后端 未结 6 602
失恋的感觉
失恋的感觉 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

    I know this answer would not have worked when the question was asked, but as this seems to be the one that people are finding when researching this issue, I thought it would be good to update with a new fix.

    For those on CF2016, Adobe has implemented a new function to help fix this issue. This would be preferable to adding a space to the front of strings, though that would still need to be the work around for releases before CF2016 as described by Sergii.

    For Structs in CF2016:

    Use the struct function, setMetadata, to specify the metadata.

    The metadata is a struct where each key is struct key and the value of each key specifies the information on how to serialize in JSON.

    The value of the key can be a string or a struct.

    Value as string

    metadata = {firstname: "string"}};

    Value as struct

    metadata = {firstname: {type: "string"}};

    Example:

    
           example = structnew();
           example.firstname = "Yes";
           example.lastname = "Man";
           // changing the default serialization by specifying the type of "firstname" as string
           metadata = {firstname: {type:"string"}};
           example.setMetadata(metadata);
           writeoutput(SerializeJSON(example));
    

    For Queries in CF11+: Adobe reports that they've fixed this issue.

提交回复
热议问题