我需要将大量 JSON 数据上传到 Web 服务。分析服务器正确接收数据并上传所有数据的最佳方法是什么?请让我知道是否有人在这方面有任何经验。谢谢。
问问题
3560 次
3 回答
2
您可以查看我的项目: https ://github.com/hidayetcolkusu?tab=repositories
计算:
ChecksumCalculator checksumCalculator = new ChecksumCalculator();
string json = @"{""Name"":""Hidayet Raşit"",""Surname"":""ÇÖLKUŞU""}";
ushort checksum = checksumCalculator.Calculate(json);
Result: 43460
比较:
ChecksumCalculator checksumCalculator = new ChecksumCalculator();
string json = @"{""Name"":""Hidayet Raşit"",""Surname"":""ÇÖLKUŞU""}";
bool result = checksumCalculator.Compare(json, 43460);
Resut:true
或者
ChecksumCalculator checksumCalculator = new ChecksumCalculator();
string json = @"{""Name"":""Hidayet Raşit"",""Surname"":""ÇÖLKUŞU"",""Checksum"":43460}";
bool result = checksumCalculator.Compare(json);
Result:true
于 2020-05-15T05:27:32.470 回答
1
您可以像这样计算 json 的哈希值:
var sha1 = System.Security.Cryptography.SHA1.Create();
byte[] buf = System.Text.Encoding.UTF8.GetBytes(jsonString);
byte[] hash= sha1.ComputeHash(buf, 0, buf.Length);
var hashstr = System.BitConverter.ToString(hash).Replace("-", "");
于 2020-05-22T22:27:24.783 回答
0
您可以计算md5来比较两个 json。
public static string CreateMD5(string json)
{
// Use json string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(json);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
于 2020-05-23T09:27:47.677 回答