Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在自定义声明(来自Auth0)中反序列化JSON?_C#_Asp.net_Json_Claims Based Identity - Fatal编程技术网

C# 如何在自定义声明(来自Auth0)中反序列化JSON?

C# 如何在自定义声明(来自Auth0)中反序列化JSON?,c#,asp.net,json,claims-based-identity,C#,Asp.net,Json,Claims Based Identity,我正在使用Auth0编写一个新的应用程序,我正在使用ASP.NET Core 1.0编写。到目前为止,它工作得很好,但由于某种原因,我遇到了一些困扰我的事情 当用户登录时,Auth0将声明传递回我的应用程序。Auth0能够向用户添加自定义数据,它以JSON格式存储,并作为声明列表显示 其中一项声明如下所示: Type "app_metadata" Value "\"IsPublisherFor\":[\"p56\",\"p124\",\"p258\"]" ValueType "JSON" 我的

我正在使用Auth0编写一个新的应用程序,我正在使用ASP.NET Core 1.0编写。到目前为止,它工作得很好,但由于某种原因,我遇到了一些困扰我的事情

当用户登录时,Auth0将声明传递回我的应用程序。Auth0能够向用户添加自定义数据,它以JSON格式存储,并作为声明列表显示

其中一项声明如下所示:

Type "app_metadata"
Value "\"IsPublisherFor\":[\"p56\",\"p124\",\"p258\"]"
ValueType "JSON"
我的问题是,我如何将索赔价值转换成我可以处理的东西?例如,执行类似
IsPublisherFor.Contains(“p56”)

我试图将该值传递给
NewtonSoft.Json.JsonConvert.DeserializeObject(value)
,但它引发了一个异常
JsonReaderException:在阅读完JSON内容后遇到的其他文本


有什么方法可以清晰地转换它吗?

您可能需要将JSON字符串用大括号括起来。通常需要一个顶级数组或对象来拥有有效的JSON。我不了解NewtonSoft,但使用JavascriptSerializer,它可以:

var json = "{\"IsPublisherFor\":[\"p56\",\"p124\",\"p258\"]}";
var serializer = new JavaScriptSerializer();
stuff obj = serializer.Deserialize<stuff>(json);

即使使用NewtonSoft,效果也很好。谢谢
public class stuff
{
    public string[] IsPublisherFor { get; set; }
}