1

I'm try to getting JSON data but getting Error.

Unexpected character encountered while parsing value: . Path '', line 0, position 0.

I'm using Net 4.5 and JSON.Net Framework Here my code

WebClient net = new WebClient();
string str = await net.DownloadStringTaskAsync(url);
JObject o = JObject.Parse(str); // ERROR Here

And my code JSON Data View on Webservice http://sv1.volcanosoft.com/test/index.php?area=ho-chi-minh this site format index.php UTF-8 and header of php file

header('Content-Type:application/json; charset=utf-8');
echo '{"item":';
echo json_encode($data);
echo '}';
9
  • I don't think str's content is as you have posted. My guess you get an error or redirect page with Html content. Commented Jan 6, 2013 at 10:33
  • Is this the JSON data in str when you debug it or before downloading the string? Commented Jan 6, 2013 at 10:33
  • Your posted JSON string seems valid as jsonlint.com says Commented Jan 6, 2013 at 10:34
  • ok. I posted JSON Data when Debug Commented Jan 6, 2013 at 10:38
  • 1
    Could you just try this without downloading the string: JObject o = JObject.Parse("...the JSON data like posted here..."); Commented Jan 6, 2013 at 10:54

1 Answer 1

2

The downloaded string starts with two byte order marks (U+FEFF), which JSON.NET parser (correctly) doesn't understand.

The reason why the downloaded string contains two BOMs is because the data your service is sending contains 3 of them. The first one is removed automatically by UTF-8 encoding, but the two other remain.

BOM can be useful with files, where you can't store the charset used. But you are sending the charset used in a header, so you don't need to send BOM at all. And sending three of them is certainly incorrect.

I believe this is caused by BOMs in your PHP files, so you should probably remove them from there.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you. It done :D . But how to convert Tiêu đề Áo khoác nữ màu da bò to Unicode ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.