Yahoo Weather arabic response contains question marks instead of arabic characters

157 views Asked by At

I am trying to use latest yahoo weather api https://weather-ydn-yql.media.yahoo.com/forecastrss It works fine but when I set language (lang=ar-AE) it returns json response with question marks instead of Arabic characters. for example "city":"????????????" For english language, it is ok.

I didn't see anything in documentation related to utf setting

When I open yahoo's weather page https://www.yahoo.com/news/weather/united-arab-emirates/abu-dhabi/abu-dhabi-1940330?lang=ar-AE it shows data in arabic, it means language code is correct

1

There are 1 answers

0
Aftab Ahmed Kalhoro On

This was the code, i used in a class to fetch weather. This code was copied from the sample code of yahoo weather documentation & modified.

            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);

I found the problem was in line

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

I changed Encoding from ASCII to UTF8 & it is working fine.