0
안녕하세요,WebClient 인코딩 문제
나에게 12kb 파일을 제공하는 CDN에서 .JSON 파일을 다운로드 중입니다. 이 파일 (export.json)을 열고 인코딩 관점에서 모든 모양이 올바른지, 표준 JSON 구문인지 확인했습니다. 나는 또한 DownloadFile 방법을 사용하여 시도했다
//webclient downloads the JSON file
var webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;
string result = string.Empty;
try
{
result = webClient.DownloadString("somewebsite/export.json");
File.WriteAllText(@"C:\Users\WebDev\Documents\Visual Studio 2015\WebSites\test\json.json", result);
}
catch (Exception ex) {
System.Diagnostics.Debug.Write(ex);
}
//parses downloaded file
Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.Parse(File.ReadAllText(@"C:\Users\WebDev\Documents\Visual Studio 2015\WebSites\test\json.json"));
//creates a dictionary at the outer object level (key=id and value=inner object
var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(o.ToString());
을 : 나는 그것을 구문 분석 할 수 있도록
나는 내 서버에 다운로드하려면 다음 코드를 사용합니다. 매번, .JSON 파일에서 " b X export.json.tmp \ R H ~ : ) u b @"를 생성합니다.
내가 누락 된 아이디어가 있습니까? 감사.
응답 헤더에서 인코딩을 가져 오는 [이 솔루션] (http://stackoverflow.com/a/30049848/3744182)을 시도하십시오. – dbc