小编Tom*_*ech的帖子

在.NET Core 2.0中调用JsonConvert.DeserializeObject <T>时缺少System.Security.Permissions

我目前正在使用.NET Core 2.0,以便可以在多个平台上运行我的应用程序。

我需要做的一件事是将一个传入的字符串并将其反序列化为一个对象。例如

var resultingObject = JsonConvert.DeserializeObject<MyDataContract>(request);
Run Code Online (Sandbox Code Playgroud)

在完整的.NET中,它将运行并返回我的对象​​。但是,在.NET Core 2.0中,出现以下异常

Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_DynamicCodeGeneration()
 at Newtonsoft.Json.Serialization.JsonTypeReflector.get_ReflectionDelegateFactory()
 at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)
 at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
 at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
 at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
 at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
 at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
 at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
 at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
Run Code Online (Sandbox Code Playgroud)

经过一番阅读后,我在StackOverflow上发现了这一点,这表明.NET Core /sf/answers/2687004211/不允许这种操作

有人有见识吗?

c# json.net .net-core

9
推荐指数
2
解决办法
2718
查看次数

从iTextSharp中的PDF获取文档属性

我正试图从PDF文件中获取一些信息.我尝试过使用PdfSharp,它具有我需要的信息属性,但它无法打开iref流,所以我不得不放弃它.

相反,我正在尝试iTextSharp.到目前为止,我已经设法从Info数组中获取一些基本信息,如标题,aurhor和subject.

但是,我现在正在获取更多信息,但无法在iTextSharp中找到它暴露的位置(如果它暴露)....我所追踪的信息在下图中突出显示:

我需要的信息

我无法弄清楚这些信息的存储位置.任何和所有的帮助将不胜感激.

c# pdf itextsharp

4
推荐指数
1
解决办法
4507
查看次数

任何div id的jQuery选择器,包含指定的数字或更高的数字

我有一个问题,我无法弄清楚如何解决!如果您有任何想法,请协助:)

在我的DOM中有一堆objets,如下所示:

<div id=Line1>1</div>
<div id=Line2>2</div>
<div id=Line3>3</div>
<div id=Line4>4</div>
<div id=Line5>5</div>
<div id=Line6>6</div>
<div id=Line7>7</div>
<div id=Line8>8</div>
<div id=Line9>9</div>
<div id=Line10>10</div>
Run Code Online (Sandbox Code Playgroud)

我需要得到一个jQuery对象,其中包含任何div是Line6-10(即包含6或更高版本)....我试过用.gt()来玩但是无济于事.

帮助将不胜感激

html jquery

2
推荐指数
1
解决办法
5336
查看次数

选择此模式中的匹配项

我试图找出一个能够应对以下条件的正则表达式:

基本上,下面的一行是一对变量及其值,用一行文字表示.

  1. 变量名称可以是A-Za-z0-9
  2. 逗号分隔对
  3. 值可以是任何值,包括equals和逗号

Variable1=somevalue1,Variable2=somevalue2,Variable3=some,value2

我希望以下匹配:

  1. Variable1=somevalue1
  2. Variable2=somevalue2
  3. Variable3=some,value2

任何帮助表示赞赏,谢谢

regex

1
推荐指数
1
解决办法
78
查看次数

序列化C#对象并保留属性名称

我试图将序列化对象发布到Web服务.该服务要求将属性名称'context'和'type'格式化为'@context'和'@type',否则它将不接受该请求.

Newtonsoft JSON.NET正在从属性名称'context'和'type'中删除'@',我需要它们进入JSON.有人可以帮忙吗?

这是我正在使用的课程

public class PotentialAction
{
    public string @context { get; set; }
    public string @type { get; set; }
    public string name { get; set; }
    public IList<string> target { get; set; } = new List<string>();
}
Run Code Online (Sandbox Code Playgroud)

这是它被转换为的JSON:

{
  "potentialAction": [
   {
      "context": "http://schema.org",
      "type": "ViewAction",
      "name": "View in Portal",
      "target": [
        "http://www.example.net"
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

但这是我需要它序列化到:

{
  "potentialAction": [
   {
      "@context": "http://schema.org",
      "@type": "ViewAction",
      "name": "View in Portal",
      "target": [
        "http://www.example.net"
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

c# json json.net

1
推荐指数
1
解决办法
100
查看次数

标签 统计

c# ×3

json.net ×2

.net-core ×1

html ×1

itextsharp ×1

jquery ×1

json ×1

pdf ×1

regex ×1