Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

User Image
小恐龙
4 discussion posts
I need using Newtonsoft.json deserialize a json.
• Attachment [protected]: 111111111.png [41,242 bytes]
Dec 28, 2021  • #1
User Image
小恐龙
4 discussion posts

Code

using System;
using System.Text;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;   //install-package newtonsoft.json ,
// The 'text' parameter will contain the text from the:
//   - Current Clipboard when run by HotKey
//   - History Item when run from the History Menu
// The returned string will be:
//   - Placed directly on the Clipboard when run as a Macro
//   - Ignored by ClipboardFusion if it is 'null'
//   - Passed along to the next action in a Trigger (null changed to an empty string)
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
Baidu AB = new Baidu();
string retString = AB.BaiduTrans(text);
if (!retString.Contains("dst"))
{
BFS.Dialog.ShowTrayMessage("Error:获取翻译失败!");
return text;
}
Root rt = JsonConvert.DeserializeObject<Root>(retString);
for (int i = 0; i < rt.trans_result.Count; i++)
{
return(rt.trans_result[i].dst);
}
}
}
public class Trans_resultItem
{
public string src { get; set; }
public string dst { get; set; }
}
public class Root
{
public string @from { get; set; }
public string to { get; set; }
public List<Trans_resultItem> trans_result { get; set; }
}
public class Baidu
{
public string BaiduTrans(string text)
{
string q = text;
string from = "auto";
string to = "zh";
// your APP ID
string appId = "";
Random rd = new Random();
string salt = rd.Next(100000).ToString();
// your key
string secretKey = "";
string sign = EncryptString(appId + q + salt + secretKey);
string url = "http://api.fanyi.baidu.com/api/trans/vip/translate?";
url += "q=" + WebUtility.HtmlEncode(q);
url += "&from=" + from;
url += "&to=" + to;
url += "&appid=" + appId;
url += "&salt=" + salt;
url += "&sign=" + sign;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text / html; charset = UTF - 8";
request.UserAgent = null;
request.Timeout = 6000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
public string EncryptString(string str)
{
MD5 md5 = MD5.Create();
byte[] byteOld = Encoding.UTF8.GetBytes(str);
byte[] byteNew = md5.ComputeHash(byteOld);
StringBuilder sb = new StringBuilder();
foreach (byte b in byteNew)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
}
Dec 28, 2021 (modified Jan 6, 2022)  • #2
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
Can you try installing this: https://www.newtonsoft.com/json

Thanks!
Jan 5, 2022  • #3
User Image
小恐龙
4 discussion posts
Quote:
Can you try installing this: https://www.newtonsoft.com/json
Thanks!

Already installed.
And copying to the \ClipboardFusion folder will not work.
Jan 6, 2022 (modified Jan 6, 2022)  • #4
User Image
小恐龙
4 discussion posts
OK. I get it.
• Attachment [protected]: ____ 2022-01-06 093003.jpg [30,079 bytes]
Jan 6, 2022  • #5
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)