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

Json parsing issue

New Here ,
Apr 16, 2015 Apr 16, 2015

Copy link to clipboard

Copied

We use the cf binaryencode function to convert a binary file to a base64 string that then is inserted into a coldfusion structure. Then we use the serizlizeJSON function to convert that structure to JSON.

When it fails we get this error:

JsonParsingError - Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character 'ﻘ' (code 0xfed8) in base64 content at [Source: java.io.StringReader@192fd063; line: 1, column: 12229]

Using the same code and the same file works correctly in CFMX 9.

We narrowed down to the serializeJSON function by manually creating the JSON string and bypassing the serializeJSON function completely.

Running CF11 Update 5 did not solve this either.

Anyone have any ideas on how to remedy this?

thanks!

- Alex

Views

1.6K

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 ,
Apr 16, 2015 Apr 16, 2015

Copy link to clipboard

Copied

Sample code please.

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
New Here ,
Apr 17, 2015 Apr 17, 2015

Copy link to clipboard

Copied

<cffile action="readbinary" file="somefile.pdf" variable="objBinaryData" />

<cfset encodedFile =  BinaryEncode(objBinaryData, "Base64")>

<cfscript> 

postOnbj = StructNew();

postOnbj["fileExtension"] = deSerData.fileExtension;

postOnbj["uploadedBy"] = deSerData.uploadedBy;

postOnbj["document"] = encodedFile;

d = SerializeJSON(postOnbj);  //fails to serialize JSON

</cfscript

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 ,
Apr 27, 2015 Apr 27, 2015

Copy link to clipboard

Copied

Not sure if it'll make any difference but the documentation for cffile readbinary says to use ToBase64(), not BinaryEncode(). I've never used BinaryEncode for anything but I have used ToBase64. If you end up with the same results, it sounds like a bug -- not unheard of. Maybe dump out the serialized JSON result and paste it into a JSON validator and see what is screwing up.

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
Community Expert ,
May 02, 2015 May 02, 2015

Copy link to clipboard

Copied

What if you use the full path, like this

<cffile action="readbinary" file="#expandPath('somefile.pdf')#" variable="objBinaryData" />

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
New Here ,
Aug 13, 2015 Aug 13, 2015

Copy link to clipboard

Copied

LATEST

We are running into the same issues.  We are storing user images into a database via binary.  Our site is heavy on the jquery side and we use ajax calls to retrieve this data.  Since json does not like binary, we have to convert the binary image into base64.  We then make an ajax call and reference our cfc to return the data.  When using returnformat=json, we have noticed that some of the base64 data was not encoded correctly.  We did string compare and noticed changes in the string.....Ben Nadal has an article that discusses these nuances in more detail.  Things like U+ gets converted to u//.  Not sure why this has not been fixed.  Seems like a simple solution from Adobe.  I hope this helps....

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