0

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

  • What are you using exactly to access the API? Are you sure the question marks are actually present in the JSON being sent by the server, and are not the result of a lossy data conversion when the JSON is passed to your code? Did you sniff the raw data that the server is actually sending? – Remy Lebeau Nov 11 '19 at 23:34
  • @RemyLebeau I am sending http request through C# code and http response comes with question marks, if I set language to arabic. – Aftab Ahmed Kalhoro Nov 12 '19 at 04:23
  • Please [edit] your question to show your actual code, to rule out any bugs in it. And you didn't answer my question - did you sniff the raw data that is actually being transmitted? – Remy Lebeau Nov 12 '19 at 06:22
  • Thanks @RemyLebeau I solved the issue & posted as answer – Aftab Ahmed Kalhoro Nov 12 '19 at 15:19

1 Answers1

0

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.