using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static async Task Main()
using (HttpClient client = new HttpClient())
HttpResponseMessage response = await client.GetAsync($"https://jsonplaceholder.typicode.com/comments?postId={POST_ID}");
response.EnsureSuccessStatusCode();
string responseData = await response.Content.ReadAsStringAsync();
List<Comment> commentList = JsonConvert.DeserializeObject<List<Comment>>(responseData);
foreach (var comment in commentList)
Console.WriteLine($"CommentID: {comment.Id} | Poster: {comment.Email}");
string encodedUrl = Uri.EscapeDataString(comment.Body);
response = await client.GetAsync($"https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q={encodedUrl}");
response.EnsureSuccessStatusCode();
responseData = await response.Content.ReadAsStringAsync();
string t = GetTranslation(responseData);
Console.WriteLine($"\t{t}");
Console.WriteLine("----------------------------------------------------");
catch (HttpRequestException e)
Console.WriteLine("Request error: " + e.Message);
public static string GetTranslation(string json)
JArray jsonArray = JArray.Parse(json);
List<string> englishTexts = new List<string>();
JArray secondArray = (JArray)(jsonArray[0]);
string result = String.Empty;
for (int i = 0; i < secondArray.Count; i++)
result += secondArray[i][0].ToString();
public int PostId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Body { get; set; }