Reputation: 2016
i'm reading Json from a web api, with Newtonsoft.Json
most of their page are fine.
But some of them may contain some special character which fail my parsing.
Code is like:
WebClient client = new WebClient();
String strJson = client.DownloadString(url);
JObject jObject = JObject.Parse(strJson );
then i try to convert to UTF8 it still no work:
WebClient client = new WebClient();
String strJson = client.DownloadString(url);
byte[] utf8Bytes = Encoding.UTF8.GetBytes(strJson);
string safeJsonStr= Encoding.UTF8.GetString(utf8Bytes);
JObject jObject = JObject.Parse(safeJsonStr);
please help!
thanks
Upvotes: 5
Views: 13196
Reputation: 2016
well, finally i find a way.
i see there are some special language, and i feel i need a decode or encode.
then finally i find this works:
client.Encoding = System.Text.Encoding.UTF8;
strJson = client.DownloadString(url);
Upvotes: 2