Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Newtonsoft Json Convert不会将Json字符串转换为对象_C#_Json - Fatal编程技术网

C# Newtonsoft Json Convert不会将Json字符串转换为对象

C# Newtonsoft Json Convert不会将Json字符串转换为对象,c#,json,C#,Json,我有这些课程 public class ResponseEntryInfoAndTollDue { public int Code { get; set; } public string Message { get; set; } public TagEntryInfo TagEntryInfo { get; set; } public TollMatrix TollMatrix { get; set; } public List<TagInfoPa

我有这些课程

public class ResponseEntryInfoAndTollDue
{
    public int Code { get; set; }
    public string Message { get; set; }
    public TagEntryInfo TagEntryInfo { get; set; }
    public TollMatrix TollMatrix { get; set; }
    public List<TagInfoParam> TagInfoParams { get; set; }
    public ResponseEntryInfoAndTollDue()
    {
        TagEntryInfo = new TagEntryInfo();
        TollMatrix = new TollMatrix();
        TagInfoParams = new List<TagInfoParam>();
    }
}

public class TagEntryInfo
{
    public long TrxnID { get; set; }
    public string TagRFIDNumber { get; set; }
    public string EntryTrxnDTime { get; set; }
    public int EntryPlaza { get; set; }
    public short EntryLane { get; set; }
    public string EntryDirection { get; set; }
    public string EntryLaneType { get; set; }
    public string PostingDateTime { get; set; }
    public string Action { get; set; }
}

public class TollMatrix
{
    public decimal TollDue { get; set; }
    public decimal TollVat { get; set; }
    public decimal TollNoVat { get; set; }
    public bool IsDefaulted { get; set; }
}

public class TagInfoParam
{
    public DateTime? AsOfDate { get; set; }
    public Decimal? AvailableBalance { get; set; }
    public string TagNumber { get; set; }
    public string PLateNumber { get; set; }
    public Int16 HonorPlate { get; set; }
    public Int16 TagStatusID { get; set; }
    public string TID { get; set; }
    public string EPC { get; set; }
    public string AccountTypeID { get; set; }
    public Int16 AccountStatusID { get; set; }
    public Int16 TagClassID { get; set; }
    public Int16 Status { get; set; }
}
我是这样转换的: var response=JsonConvert.DeserializeObject(ret)

我知道它不会被转换,因为这是我得到的:

结果是:


为什么不将其转换为对象?

因为Fabio还提到,json包含属性
Result
,该属性不是对象的一部分,因此可以使用下面的逻辑进行反序列化

var jObj = JObject.Parse(json);
var responseEntryInfoAndTollDue = JsonConvert.DeserializeObject<ResponseEntryInfoAndTollDue>(jObj["Result"].ToString());
var jObj=JObject.Parse(json); var responseEntryInfoAndTollDue=JsonConvert.DeserializeObject(jObj[“Result”].ToString()); 上面的代码首先将Json解析为
JObject
,并使用
Result
属性反序列化为
responseEntryInfo和tollDue
对象


检查这把小提琴-

@Fabio抱歉,我没能把它包括进去。请查看我的编辑。如何验证它未反序列化?您收到异常了吗?示例中的Json字符串具有“attribute”
Result
,但您提供的所有类型都没有异常。@Fabio我没有收到任何异常。那么我应该创建一个类结果吗?
var jObj = JObject.Parse(json);
var responseEntryInfoAndTollDue = JsonConvert.DeserializeObject<ResponseEntryInfoAndTollDue>(jObj["Result"].ToString());