json_decode中的PHP额外字符

the last.fm API is returning a JSON string which I convert to an array using

json_decode($response, ($returnType == 'array'));

When the response is dumped it gives me the following json string:

{"session":{"name":"turncoat9","key":"b311abDee2d34e07541eeeefted2bad","subscriber":"0"}} 1

(note the 1 in the end)

Because of this extra character the json string cannot be converted to an associative array, hence my problem.

I found a few discussions which state that the 1 is a BOM (byte order mask) character, but all solutions provided does not work with my json string.

What is this character? Why is it there and why does this not happen when I develop locally? What is the solution for this?

Tried this on two different webservers, gave the same result

You can remove it using trim:

$cleaned_json = trim($received_json, '1 ');

Manual

First, I do not understand ($returnType == 'array'), you should only put TRUE there

assoc->When TRUE, returned objects will be converted into associative arrays.

Second, what answer do you get from your API? Are you sure it returns only the json string?