我有以下代码来序列化JSON字符串:
string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray()); // token creation
DateTime Minutes = DateTime.Now.AddMinutes(25);
StringEncryption stringEncryption = new StringEncryption();
var sso = "MY_SSO_KEY";
OnlineProfile onlineProfile = new OnlineProfile();
onlineProfile.first_name = "John";
onlineProfile.last_name = "Doe";
onlineProfile.email = "johndoe@multisite.com";
onlineProfile.expires = Minutes.ToString();
onlineProfile.url = "https://www.multisite.com";
onlineProfile.SSO = stringEncryption.Encrypt(sso);
onlineProfile.signature = stringEncryption.SignData(token);
JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Ignore;
using (StreamWriter sw = new StreamWriter(@"c:json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer, onlineProfile);
}
上面的代码生成以下JSON数据输出:
//{"email":"johndoe@multisite.com",
//"expires":"10/11/2018 14:25:00 PM",
//"first_name":"John",
//"last_name":"Doe",
//"url":"https://www.multisite.com",
//"SSO":"MY_SSO_KEY_ENCRYPTED",
//"signature":"TOKEN"}
使用该JSON数据可以形成以下url:
http://www.multisite.com/sso?sso=MY_SSO_KEY_ENCRYPTED&signature=TOKEN
如何形成上面的url?非常感谢你的帮助!
尝试UrlBuilder
尝试UrlBuilder