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 '}';
RaymondLe
  • 147
  • 3
  • 11

1 Answers1

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.

svick
  • 236,525
  • 50
  • 385
  • 514