using Newtonsoft.Json; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; namespace AIProofread { public class Tools { public static string GetAllText() { // 获取当前文档所有文本 string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text; List list = new List(); if (allText != null && allText.Length > 0) { // 开始分割 MD5 md5 = new MD5CryptoServiceProvider(); List lines = StringUtil.CutTextToSentences(allText); foreach (string text in lines) { byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text)); list.Add(new DocumentText(hash, text)); } } var map = new Dictionary { { "list", list }, { "text", allText } }; return GetJSONString(map); } public static string GetJSONString(object data) { return JsonConvert.SerializeObject(data, Formatting.Indented); } } }