• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF11: serializejson generate invalid json format

New Here ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

I migrated my application from CF9 to CF11, and got a serializejson issue. When serialize object data with empty string,  the serializejson function generates invalid string.

I have function getConfiguration in A.cfc and function getImageResult in B.cfc. The function getConfiguration would get an object data and serialize them to json, then return the json data. Below are the object data and the generated invalid json. In this case, I would got json parsing error when deserialize json in getImageResult function.

Object data:

{

      RESULT: true

      MESSAGE: call function getConfiguration successfully

      OBJECT: {

          HID: [empty string]

         TF_LAB_USE_DOCUMENT_MANAGEMENT: [empty string]

         PARENT_HID: [empty string]

      }

     CODE: [empty string]

  }

json:

{""MESSAGE"":""call function getConfiguration successfully"",""CODE"":"""",""OBJECT"":{""HID"":,""PARENT_HID"":,""TF_LAB_USE_DOCUMENT_MANAGEMENT"":},""RESULT"":true,""VALIDATIONMESSAGE"":""""}"

   

Do we have solutions to fix this problem? Thanks for help

Views

757

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

I have not heard anything about there being a fix for your issue.  I believe that CF serializeJSON also incorrectly inserts "no" as "false".  Or was it zero as false, I can't remember.  I think Ben Nadel created a JSON function that will properly encode.

HTH,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

LATEST

It appears that SerializeJSON is being called twice, once on the structure and once on the results of the serialized string of the structure. I use serializeJSON all the time and have not seen what you are describing (although there are other issues, like assuming that "9" and 9 both serialize as 9, or "true" and true).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

Hey Lucial,

Fear not. I ran into this myself. You can cut an paste this code and change it to your needs. Please note, I changed the <cfhttp> request to add (getasbinary="never") and (result="getdata") in case you are using multiple cfhttp requests on the same page.

<!--- Get the JSON Feed --->

<cfhttp getasbinary="never" result="getdata" url="http://localhost:8500/My_Stuff/Ajax/Books/CreateJSON_NEW.cfm">

<!--- JSON data is sometimes distributed as a JavaScript function.

  The following REReplace functions strip the function wrapper. --->

<cfset theData=REReplace(getdata.FileContent, 

  "^\s*[[:word:]]*\s*\(\s*","")>

<cfset theData=REReplace(theData, "\s*\)\s*$", "")>

Source: Adobe ColdFusion 9 * DeserializeJSON

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation