Response of FileTransfer Upload cannot be parsed into JSON

Hello,
I have a strange problem:
I upload a file to my server with FileTransfer and i want to process the response of the server on the client.
The response is this string: "{“error”:false,“new_name”:“596108fe2b63d7.14487709.jpg”}"
But when i run JSON.parse on this string i get an “SyntaxError: Unexpected token  in JSON at position 0”.

If i run an external validation on this string, it is valid to be used as JSON

Anyone has an idea, whats the problem here?

Thanks
Skee

How exactly do you get that result, what is your code?
Can you console.log the result?

Are the quotes surrounding the entire string there in reality?

Parse file transfer’s result yesterday without any error. Check ur code or server response. May be server send ur broken JSON?

Ok, looks like the error was on my side:
When i copied all the data together, to post it here, i realised that the was a whitespace at the beginning of data.response, which was not visible in the chrome console but in my text editor.
So i just run trim() before parsing and everything works just fine :slight_smile:
Thanks for helping.

Skee

2 Likes