Hello,

So this tripped me up. I was reading a url that returned a json with a BOM, online json validators reported it as valid json but php's json_decode() was returning null.

I found the solution here :

http://stackoverflow.com/questions/9232109/json-encode-returning-null-fo...

While this solution can easily be implemented as a custom parser, I thought it might be useful for wsdata to be able to deal with it by default.

Patch incoming.

CommentFileSizeAuthor
#2 remove_utf8_bom_json-2660508-2.patch596 bytesptsimard
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ptsimard created an issue. See original summary.

ptsimard’s picture

Status: Active » Needs review
FileSize
596 bytes

Here is the patch adding this code to wsdata_simple_json.wsdata.processor.inc:

// Remove UTF-8 BOM if present, json_decode() does not like it.
if(substr($data, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) {
  $data = substr($data, 3);
}
ptsimard’s picture

Issue summary: View changes
dmitryVL’s picture

Status: Needs review » Reviewed & tested by the community

Also have the same problem and use that(http://stackoverflow.com/questions/9232109/json-encode-returning-null-fo...) solution, so looks good and move to rtbc.

  • spotzero committed 7bc3c8c on authored by ptsimard
    Issue #2660508 by ptsimard: Simple json parser fails when json contains...
spotzero’s picture

Status: Reviewed & tested by the community » Fixed

Fix committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.