Hi Shahzad786,
WebClient.DownloadString uses WebClient.Encoding as its encoding when it converts the remote resource into a string.
Set it to System.Text.Encoding.UTF8.
Check the below code.
Using the below article i have modified the code.
C#
protected void Translate(object sender, EventArgs e)
{
string url = "https://translation.googleapis.com/language/translate/v2?key=API_Key";
url += "&source=" + ddlSource.SelectedItem.Value;
url += "&target=" + ddlTarget.SelectedItem.Value;
url += "&q=" + Server.UrlEncode(txtSource.Text.Trim());
WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
string json = client.DownloadString(url);
JsonData jsonData = (new JavaScriptSerializer()).Deserialize<JsonData>(json);
txtTarget.Text = jsonData.Data.Translations[0].TranslatedText;
}
public class JsonData
{
public Data Data { get; set; }
}
public class Data
{
public List<Translation> Translations { get; set; }
}
public class Translation
{
public string TranslatedText { get; set; }
}
VB.Net
Protected Sub Translate(sender As Object, e As EventArgs)
Dim url As String = "https://translation.googleapis.com/language/translate/v2?key=API_Key"
url += "&source=" + ddlSource.SelectedItem.Value
url += "&target=" + ddlTarget.SelectedItem.Value
url += "&q=" + Server.UrlEncode(txtSource.Text.Trim())
Dim client As New WebClient()
client.Encoding = System.Text.Encoding.UTF8
Dim json As String = client.DownloadString(url)
Dim jsonData As JsonData = (New JavaScriptSerializer()).Deserialize(Of JsonData)(json)
txtTarget.Text = jsonData.Data.Translations(0).TranslatedText
End Sub
Public Class JsonData
Public Property Data() As Data
End Class
Public Class Data
Public Property Translations() As List(Of Translation)
End Class
Public Class Translation
Public Property TranslatedText() As String
End Class
Screenshot