开发者

De-sererialzing JSON using JSONConvert - doesn't compile

开发者 https://www.devze.com 2023-03-22 09:02 出处:网络
I\'m using VS2008.I\'ve referenced the Newtonsoft.Json (Json.Net) library (v. 3.5) (just the dll...didn\'t see documentation on what to do with the .pdb and xml file).I\'m running .Net 3.5 on server 2

I'm using VS2008. I've referenced the Newtonsoft.Json (Json.Net) library (v. 3.5) (just the dll... didn't see documentation on what to do with the .pdb and xml file). I'm running .Net 3.5 on server 2k3. Other webmethods within the file are successfully using Serialization.Json.

No errors indicated by IntelliSense... but it wont compile. Giving 'The type or namespace' var could not be found. (indicated by the 'v').

using Newtonsoft.Json;
[WebMethod(EnableSession = true)]
public string EvaluationTest(String EvalData)
{   v
   var EvalList = JsonConvert.DeserializeObject<EvaluationCollection>(EvalData);开发者_JAVA技巧
   int rowscount = EvalList.Eval.Count;
   int firstobject = EvalList.eval.es;
}

my classes:

namespace MyNamespace
{
   public abstract class EvaluationCollection
   {
    public abstract OneEvaluation eval { get; set; }
    private List<OneEvaluation> _eval = new List<OneEvaluation>();

    public List<OneEvaluation> Eval = new List<OneEvaluation>();

    public EvaluationCollection()
    {
    }
   }

public class OneEvaluation
{
    private int _EvalSession = 0;
    private String _Comment = " ";
    private String _DataDate;

    public OneEvaluation()
    {
    }

    public int es        {   // EvalSession
        get { return _EvalSession; }
        set { _EvalSession = value; }
    }
    ...
   }
  }

I'm wondering... did I not reference this correctly?


The problem with this approach... was my web.config.

For those interested... I have both vb and c# on the website - and I needed to add the following section

<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="v3.5"/>
                <providerOption name="WarnAsError" value="false"/>
            </compiler>
        </compilers>
    </system.codedom>
0

精彩评论

暂无评论...
验证码 换一张
取 消