Yahoo Weather阿拉伯语响应包含问号而不是阿拉伯字符

时间:2019-11-11 06:07:48

标签: utf-8 arabic yahoo-weather-api

我正在尝试使用最新的Yahoo Weather API https://weather-ydn-yql.media.yahoo.com/forecastrss 它工作正常,但是当我设置语言(lang = ar-AE)时,它返回带有问号而不是阿拉伯字符的json响应。例如 “ city”:“ ????????????” 对于英语,可以。

我在与utf设置有关的文档中没有看到任何内容

当我打开雅虎的天气页面https://www.yahoo.com/news/weather/united-arab-emirates/abu-dhabi/abu-dhabi-1940330时? lang = ar-AE ,它以阿拉伯语显示数据,这表示语言代码正确

1 个答案:

答案 0 :(得分:0)

这是代码,我在课堂上用它来获取天气。该代码是从yahoo天气文档的示例代码复制而来的。

describe('Apple', () => {
    test('test function1()', () => {
        Apple.doSomething = jest.fn().mockImplementation((2) => {
            // do something;
        });

        let apple = new Apple(data); // the original doSomething() executes here instead of the mocked version
    });
});

我发现问题出在

            string lURL = cURL + "?" +  cWeatherID + "&" + cUnitID + "&format=" + cFormat + string.Format("&lang={0}", this.Lang);

        var lClt = new WebClient();

        lClt.Headers.Set("Content-Type", "application/" + cFormat);
        lClt.Headers.Add("X-Yahoo-App-Id", this.AppID);
        lClt.Headers.Add("Authorization", _get_auth());

        byte[] lDataBuffer = lClt.DownloadData(lURL);

        string result = Encoding.ASCII.GetString(lDataBuffer);

我将编码从 ASCII 更改为 UTF8 ,并且工作正常。