如何将jsonarray添加到字典中

时间:2017-07-24 05:05:51

标签: json dictionary token

如何将对象列表添加到字典中作为json数组? 我的代码是:

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);
    }

我想将角色列表添加为json数组,但是将其作为字符串添加到字典中。

0 个答案:

没有答案