C# Can';不要在Windows通用应用程序中使用JavaScriptSerializer
我在Visual Studio 2017 C#console应用程序中从web服务获取JSON数据,将JSON数据反序列化为三个字符串。然后我将代码移动到Windows10通用应用程序中 反序列化代码不会在UWP程序中编译,因为类型JavaScriptSerializer不可用。我无法将System.Web.Extensions添加到系统(引用/程序集/框架),当我的Windows 10解决方案打开时,我从VS 2017收到此消息,“在计算机上找不到框架程序集” 以下是JSON字符串:C# Can';不要在Windows通用应用程序中使用JavaScriptSerializer,c#,uwp,C#,Uwp,我在Visual Studio 2017 C#console应用程序中从web服务获取JSON数据,将JSON数据反序列化为三个字符串。然后我将代码移动到Windows10通用应用程序中 反序列化代码不会在UWP程序中编译,因为类型JavaScriptSerializer不可用。我无法将System.Web.Extensions添加到系统(引用/程序集/框架),当我的Windows 10解决方案打开时,我从VS 2017收到此消息,“在计算机上找不到框架程序集” 以下是JSON字符串: {
{
"Snippet":"\"Special counsel ...\"",
"SnippetDate":"9/9/2017 12:00:00 AM",
"SnippetSource":"The Washington Post"
}
以下是在console项目(而不是Windows 10项目)上编译和运行的代码段
using System.Web.Script.Serialization;
.
.
.
public class NewsSnippet
{
public string Snippet { get; set; }
public string SnippetDate { get; set; }
public string SnippetSource { get; set; }
}
.
.
.
var serializer = new JavaScriptSerializer();
var deserializedResult = serializer.Deserialize<NewsSnippet>(jsonString);
使用System.Web.Script.Serialization;
.
.
.
公共类新闻片段
{
公共字符串片段{get;set;}
公共字符串代码段日期{get;set;}
公共字符串代码段源{get;set;}
}
.
.
.
var serializer=新的JavaScriptSerializer();
var deserializedResult=序列化程序。反序列化(jsonString);
在通用Windows应用程序中反序列化JSON字符串有哪些替代方法?您应该能够通过
var deserializedResult=JsonConvert.DeserializeObject(jsonString);
var source=反序列化dResult.SnippetSource;
Lookup Newtonsoft的Json.netJsonConvert.DeserializeObject(jsonString)代码>
var deserializedResult = JsonConvert.DeserializeObject<NewsSnippet>(jsonString);
var source = deserializedResult.SnippetSource;