如何将jsonarray添加到字典中
如何将对象列表作为json数组添加到字典中? 我的代码是:如何将jsonarray添加到字典中,json,dictionary,token,Json,Dictionary,Token,如何将对象列表作为json数组添加到字典中? 我的代码是: public override Task TokenEndpoint(OAuthTokenEndpointContext context) { var role = new UserAccount().GetUserRolesList(context.Identity.Name); context.AdditionalResponseParameters.Add("userName",conte
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
var role = new UserAccount().GetUserRolesList(context.Identity.Name);
context.AdditionalResponseParameters.Add("userName",context.Identity.Name);
var jsonRole = JsonConvert.SerializeObject(role.Select(x => new {x.RoleId,x.Title}),Formatting.None);
context.AdditionalResponseParameters.Add("roles",jsonRole);
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
{
context.AdditionalResponseParameters.Add(property.Key, property.Value);
}
return Task.FromResult<object>(null);
}
public覆盖任务令牌端点(OAuthTokenEndpointContext)
{
var role=new UserAccount().GetUserRolesList(context.Identity.Name);
AdditionalResponseParameters.Add(“用户名”,context.Identity.Name);
var jsonRole=JsonConvert.SerializeObject(role.Select(x=>new{x.RoleId,x.Title}),Formatting.None);
AdditionalResponseParameters.Add(“角色”,jsonRole);
foreach(context.Properties.Dictionary中的KeyValuePair属性)
{
AdditionalResponseParameters.Add(property.Key,property.Value);
}
返回Task.FromResult(空);
}
我想将角色列表添加为json数组,但将其作为字符串添加到字典中。什么不起作用?你在努力解决什么具体问题?你有什么错误吗?结果是:“角色”:“[{“RoleId\”:1,\“Title\”:“admin\”},{“RoleId\”:2,\“Title\”:“user\”}]”但是我想要json数组,比如:“roles:[{“RoleId”:1,“Title:”admin“},{“RoleId”:2,“Title:”user“}”,你知道怎么做吗?