以前、Newtonsoft.Json を使用して JSON の逆シリアル化に成功しましたが、この単純な例で問題が発生しました。デバッガの表示: ServiceResponse.StatusInfo = null、ServiceResponse.Email = null、ServiceResponse.JobId = 0
// Generated by Xamasoft JSON Class Generator
// http://www.xamasoft.com/json-class-generator
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Example.fmeResponseJsonTypes;
namespace Example.fmeResponseJsonTypes
{
public class StatusInfo
{
[JsonProperty("mode")]
public string Mode { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
}
public class ServiceResponse
{
[JsonProperty("statusInfo")]
public StatusInfo StatusInfo { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
[JsonProperty("jobID")]
public int JobID { get; set; }
}
}
namespace Example
{
public class fmeResponse
{
[JsonProperty("serviceResponse")]
public ServiceResponse ServiceResponse { get; set; }
public void Deserialize()
{
string res = "{\"serviceResponse\": {\"statusInfo\": {\"mode\": \"async\",\"status\": \"success\"},\"email\": \"tor.nielsen@xxx.com\",\"jobID\": 73}}";
ServiceResponse serviceResponse = null;
try
{
serviceResponse = JsonConvert.DeserializeObject<ServiceResponse>(res);
}
catch (Exception e)
{
throw new Exception("Error: Deserialization of [" + res + "] failed! \nDetails: " + e.Message + "\nTrace: " + e.StackTrace);
}
}
}
}