public string appid = "自己的APPID";
public string q = "要翻译的文本";
public string salt = "";
public string key = "你的密钥";
public string from = "你的源语言例如zh";
public string to = "要翻译成的语言例如en";
public string GetJson()
{
var client = new RestClient("http://api.fanyi.baidu.com");
var request = new RestRequest("/api/trans/vip/translate", Method.GET);
request.AddParameter("q", q);
request.AddParameter("from", from);
request.AddParameter("to", to);
request.AddParameter("appid", appid);
request.AddParameter("salt", salt);
request.AddParameter("sign", getMd5());
IRestResponse response = client.Execute(request);
return response.Content;
}
public string sign
{
get { return string.Format("{0}{1}{2}{3}", appid, q, salt, key); }
}
string getMd5()
{
var md5 = new MD5CryptoServiceProvider();
var result = Encoding.UTF8.GetBytes(sign);
var output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "").ToLower();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = GetResult();
}
public string GetResult()
{
var lst = new List<string>();
var content = GetJson();
dynamic json = JsonConvert.DeserializeObject(content);
foreach (var item in json.trans_result)
{
lst.Add(item.dst.ToString());
}
return string.Join(";", lst);
}

要引用Newtonsoft.Json.dll

https://download.csdn.net/download/jsqdragoon/10032906?web=web

最新文章

  1. 动态给div中新增html
  2. T-Sql(五)xml操作
  3. Win7全自动精简批处理_温柔处理极速修正版/暴力剩女工程测试版
  4. RTMP协议
  5. 华为手机Edittext光标(cursor)颜色修改
  6. [LeetCode]题解(python):059-Spiral Matrix II
  7. Using Post_Query Trigger in Oracle Forms
  8. HTML 表单验证和事件
  9. ruby1.8到2.1语法改变
  10. yii中上传图片及文件
  11. ASM上的备份集如何转移到文件系统中
  12. elasticsearch 中文分词、插件的安装和使用(一)
  13. Android 音视频开发(一) : 通过三种方式绘制图片
  14. BugPhobia开发篇章:Beta阶段第VII次Scrum Meeting
  15. 【学习笔记】sklearn数据集与估计器
  16. sublime text3 下配置python3!
  17. Windows8下安装ubuntu
  18. go语言,golang学习笔记2 web框架选择
  19. Vivado使用技巧(1)
  20. .Net C#上传文件最大设置

热门文章

  1. maven install 打包 报错 Cannot run program &quot;gpg.exe&quot;: CreateProcess error
  2. Web前后端分离知识整理
  3. IDA动态调试so文件出现SIGILL
  4. 【K8S学习笔记】Part3:同一Pod中多个容器间使用共享卷进行通信
  5. [Node.js] 3、搭建hexo博客
  6. Docker基础-镜像操作
  7. Linux下安装SQL Server 2016(安装篇SQL Server on linux)
  8. Java基础——TreeSet
  9. 【Linux】查看所使用的Linux系统是32位还是64 位的方法
  10. JavaScript高级编程———JSON