我有 JSON 数据:
var decodedJson =
"{{
"user": {
"userId": "sid:C4F4E93856104F078A11FE95892F0158"
},
"authenticationToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmdWxscm93IjoiYWxsIiwiRGJnMiI6ImxvZ2luIiwidmVyIjoiMyIsInVpZCI6InNpZDpDNEY0RTkzODU2MTA0RjA3OEExMUZFOTU4OTJGMDE1OCIsImlzcyI6InVybjptaWNyb3NvZnQ6d2luZG93cy1henVyZTp6dW1vIiwiYXVkIjoidXJuOm1pY3Jvc29mdDp3aW5kb3dzLWF6dXJlOnp1bW8iLCJleHAiOjE0NDk3NTYzNzIsIm5iZiI6MTQ0NzE2NDM3Mn0.kc-0O_aorfTw9l9U6yY6wyVtQnckqNBJikBzxAcJZ_U"
}}";
然后我想使用 JSON.NET 动态反序列化它:
var result = JsonConvert.DeserializeObject<dynamic>(decodedJson);
然后我希望像这样提取 UserId 和 Token:
string userId = result.user.userId;
string userToken = result.authenticationToken;
但它在说
“未知成员用户/ authenticationToken”
有任何想法吗?
更新:
我复制了错误的json数据,实际上应该是这样的:
{\"user\":{\"userId\":\"sid:C4F4E93856104F078A11FE95892F0158\"},\"authenticationToken\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmdWxscm93IjoiYWxsIiwiRGJnMiI6ImxvZ2luIiwidmVyIjoiMyIsInVpZCI6InNpZDpDNEY0RTkzODU2MTA0RjA3OEExMUZFOTU4OTJGMDE1OCIsImlzcyI6InVybjptaWNyb3NvZnQ6d2luZG93cy1henVyZTp6dW1vIiwiYXVkIjoidXJuOm1pY3Jvc29mdDp3aW5kb3dzLWF6dXJlOnp1bW8iLCJleHAiOjE0NDk3NjE1NDEsIm5iZiI6MTQ0NzE2OTU0MX0.oVH8R2134UQQDpXfzPv2mmrj7M05w2mzWtbp70i7GEU\"}