JSON REST Web サービスを使用するように求めます。
私のクラスは次のとおりです。
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace WFAEsura
{
[DataContract]
class JsonResponse
{
[DataMember]
public string status { get; set; }
[DataMember]
public Result result { get; set; }
}
class Result
{
public string studentStatus { get; set; }
public List<Results> results { get; set; }
}
class Results
{
public string code { get; set; }
public string description { get; set; }
public double creditAmount { get; set; }
public int timeUnit { get; set; }
public string mark { get; set; }
public bool passed { get; set; }
public string staffMemberName { get; set; }
public List<Results> subResults { get; set; }
}
}
これらのクラスを作成するために、私は
http://json2csharp.com/
を使用しました
私のメインクラスは
var syncClient = new WebClient();
string content = syncClient.DownloadString(baseUrl);
// Create the Json serializer and parse the response
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(JsonResponse));
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
{
// deserialize the JSON object
var jsonResponse = (JsonResponse)serializer.ReadObject(ms);
}
しかし、インラインで は、 jsonResponse = (JsonResponse)serializer.ReadObject(ms)
invalidDataContractException WFEsura.Result をシリアル化できません。
説明: System.Runtime.Serialization.dll で、タイプ 'System.Runtime.Serialization.InvalidDataContractException' の未処理の例外が発生しました
Additional information: Type 'WFAEsura.Result' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
App.configで私は
<起動> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </スタートアップ>
私は何を間違っていますか?