可以使用NewtonSoft吗?Json在T4模板中

本文关键字:T4 Json NewtonSoft 可以使 | 更新日期: 2023-09-27 18:07:04

我想在T4模板中反序列化一些JSON。我已经引用了程序集和所有这些,它看起来都很好,但是当我调用这个:

var root = JsonConvert.DeserializeObject<RootObject>(response);

我得到这个:

Error   4   Running transformation: System.TypeLoadException: Could not find Windows Runtime type 'Windows.Data.Json.IJsonValue'. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Converters.JsonValueConverter.CanConvert(Type objectType)
   at Newtonsoft.Json.JsonSerializer.GetMatchingConverter(IList`1 converters, Type objectType)
   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)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at Microsoft.VisualStudio.TextTemplating051377DF83FAD6CEB531E8C53BDF7AF0925D52AE4E0D72D32E8A27AD05041FA9D55204F2BCFCC44A6977B1EA4AD1DA5E9682BFE9EB924836019C6E14E1AED232.GeneratedTextTransformation.GetInfoForCountries() in c:'************'CalabashTestGeneration'Template1.tt:line 117
   at Microsoft.VisualStudio.TextTemplating051377DF83FAD6CEB531E8C53BDF7AF0925D52AE4E0D72D32E8A27AD05041FA9D55204F2BCFCC44A6977B1EA4AD1DA5E9682BFE9EB924836019C6E14E1AED232.GeneratedTextTransformation.TransformText() in c:'****************'CalabashTestGeneration'Template1.tt:line 24  c:'*************'CalabashTestGeneration'Template1.tt    117 1   CalabashTestGeneration

这可能吗?我不明白为什么T4不能使用newtonsoft,但这暗示它不能!

可以使用NewtonSoft吗?Json在T4模板中

我最终使用restsharp -似乎到目前为止工作