- Home /
Parsing Json from www response
Hi,
I have webService that return to my Unity apllication a Json response. I use the www class. When I retreive he response with the response.text and I try to parse it with my JsonParser ( I use the Json.Net), it make me this error : " JsonReaderException: Unexpected character encountered while parsing value: . Path '', line 0, position 0"
When I replace the response by a static String the same that my server reply with it works fine.!!! I log the response.text from Unity to a Json Validator, it told me that isn't valide. My response began with a hiden a hidden caracter that I supposed that response of the www class add to my server reply!!! I use the Unity 4.6 is that a Bug for this version or what!? Please help!!
Sounds to me like an issue on the server. Sometimes the server introduces characters into the output.
No it isn't from the server because wen I get the response from the server not with Unity by Postman fro example the response is validate by the json validator.
Thanks Andres Fernandez the solution of retreiving the 3 byte un the beginning is working for mee!! but is weird behaviour!! Espacially that i had some webservices that used to work and when I update my Unity to 4.6 version they are broken !!
The problem is not just the first three bytes. The problem is that WWW.text property includes the BO$$anonymous$$ of the file (if it has BO$$anonymous$$). As JSON must be UTF8 encoded, if the file has BO$$anonymous$$ included, it is just 3 bytes long (EF BB BF), but other encodings have other BO$$anonymous$$ length.
So, if you are retrieveing a file using WWW.text and the file is UTF8 encoded, then check for the UTF8 BO$$anonymous$$ . If present, then skip those bytes.
Answer by tarek-hentati · Dec 12, 2014 at 09:42 AM
Hi, I could resolve my problem with this solution posted in this url : http://answers.unity3d.com/questions/844423/wwwtext-not-reading-utf-8-text.html
Answer by abi-kr01 · Dec 11, 2014 at 11:34 AM
there must be other text after your json string like
{"user_ id":0, "token":"sdddas"} <html>bla bla bla</html>
.Json parser is trying to parse that too which is causing issue.
No there was some byte from the encode UTF8 that is boking my json structure. The sollution is what Andres Fernandez comment in my question
Your answer
Follow this Question
Related Questions
Upload/store string to html/json script?? 0 Answers
Integrating Watson Speech-to-Text with Unity 1 Answer
I cant get response json from rest call in Unity 1 Answer
iPhone bad URL 0 Answers