Microsoft Visual Studio 2010 Ultimate(版本 10.0.40219.1 SP1Rel)。
Microsoft .NET 框架版本 4.5.50709 SP1Rel
我正在编译为 .net 框架 4.0。
每当我尝试使用动态或 var 数据类型时,都会收到主题行中显示的错误:
找不到类型或命名空间名称“动态”。
找不到类型或命名空间名称“var”。
我正在尝试使用 JsonFX 解析从另一个 Web 服务接收到的数据。有时用数据会代表一个“信息”,有时它会代表一个“轨迹”。根据this JsonFx Documentation,我应该能够遵循“序列化到/从动态类型(默认为.NET 4.0)”的示例:
我在我的网站上添加了一个名为 test 的页面。下面的代码块来自 Test.aspx.cs 我尝试使用的代码是这样的:
using System;
using System.Text;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JsonFx;
using JsonFx.Json;
using Microsoft.CSharp;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string Data = "";
Data = @"[{""meta"":{""account"":""orbitinte"",""event"":""track""},""payload"":{""id"":410827200397312213,""id_str"":""410827200397312213"",""asset"":""359551031717134"",""recorded_at"":""2013-02-07T15:59:04Z"",""received_at"":""2013-02-07T16:00:37Z"",""fields"":{}}},{""meta"":{""account"":""orbitinte"",""event"":""track""},""payload"":{""id"":410827200409895125,""id_str"":""410827200409895125"",""asset"":""359551031717134"",""recorded_at"":""2013-02-07T16:00:04Z"",""received_at"":""2013-02-07T16:00:37Z"",""fields"":{}}}]";
Data = @"[{""meta"":{""account"":""orbitinte"",""event"":""message""},""payload"":{""id"":410865901198377173,""thread_id"":null,""parent_id"":410865891354345685,""id_str"":""410865901198377173"",""thread_id_str"":"""",""parent_id_str"":""410865891354345685"",""type"":""message"",""channel"":""com.mdi.services.adminProtocol"",""sender"":""359551031717134"",""recipient"":""@@server@@"",""asset"":""359551031717134"",""b64_payload"":""eyJlcnJvciI6ImNhbm5vdCBwYXJzZSBjb21tYW5kIn0="",""recorded_at"":""2013-02-07T18:34:25Z"",""received_at"":""2013-02-07T18:34:24Z""}}]";
JsonReader Reader = new JsonReader();
dynamic Output = Reader.Read(Data);
Notifications oNotifications = new Notifications();
oNotifications.ProcessNotifications(Data);
}
}
在 web.config 文件中:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
我对 C# 和 asp.net 相当陌生。但我一直在寻找解决这个问题的方法。我看到的所有内容都提到了编译器版本和 .net 框架版本。我想我已经提供了所有相关的细节,但如果我还有什么需要补充的,请告诉我。