【发布时间】:2017-03-31 20:40:09
【问题描述】:
我的 wcf 服务使用包装格式正文样式。当我尝试使用 DataContractJsonSerializer 反序列化它时,没有正确反序列化 json
SignInResult returnedUser = new SignInResult();
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(provider.SignIn(username, password)));
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SignInResult),"root");
returnedUser = serializer.ReadObject(stream) as SignInResult;
stream.Close();
return returnedUser;
但我没有得到根据以下 json 填充的对象
{
"SignInResult": {
"CreationDate": "/Date(1480598102923+0000)/",
"Email": "bladsa@as.com",
"IsApproved": true,
"IsLockedOut": false,
"IsOnline": true,
"IsValidLogin": true,
"LastActivityDate": "/Date(1490954750307+0100)/",
"LastLockoutDate": "/Date(-6816268800000+0000)/",
"LastLoginDate": "/Date(1490954750307+0100)/",
"LastPasswordChangedDate": "/Date(-2208988800000+0000)/",
"ProviderName": "LoginProvider",
"ProviderUserKey": "dcc5f38f-f71e-4d9d-bdb2-58fb60b7a65e",
"UserName": "schoi"
}
}
如果我使用裸格式,它确实有效,因此它肯定与包装的消息格式有关。
我知道我可以在 Newsoft json 中做到这一点,但我知道我会被要求使用微软的方式。
【问题讨论】: