我正在以json格式得到来自api的响应,我已将json响应编码存储在表中。我想解码响应并对其进行解密。 当我尝试解码数据时,收到错误。
错误:输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。
json中的实际响应:
data={"Id": "234", "Name": "pinky", "MobileNumber": "", "ClassName": "Class1_Physics", "DOBTime": "1990-04-11 15:46:38", "Landline": "", "Status": "Unmarried"}
编码后:
数据%3D%7B%22Id%22%3A%20%22234%22%2C%20%22Name%22%3A%20%22pinky%22%2C%20%22MobileNumber%22%3A%20%22 %22%2C%20%22ClassName%22%3A%20%22Class1_Physics%22%2C%20%20%20%22DOBTime%22%3A%20%221990-04-11%2015%3A46 3A38%%22%2C %20%22Landline%22%3A%20%22%22%2C%20%22Status%22%3A%20%22Unmarried%22%7D%0A
我已经采用了一种解码工具的帮助。 代码: //获取存储在数据库中的响应并分配给名为' Name'
的字符串string base64Decoded, base64Decoded2;
base64Decoded = Name.Trim();
base64Decoded = base64Decoded.Replace('-', '+');
base64Decoded = base64Decoded.Replace('_', '/');
base64Decoded = base64Decoded.Replace('=', '/');
base64Decoded = base64Decoded.Replace(':', '/');
byte[] data2 = System.Convert.FromBase64String(base64Decoded);
base64Decoded2 = System.Text.ASCIIEncoding.ASCII.GetString(data2);
在此行获取错误:
byte [] data2 = System.Convert.FromBase64String(base64Decoded);