[英]Deserializing Json Response to a Dictionary<string, object> throws error : unexpected end when deserializing object
嗨,我正在嘗試反序列化json響應,如下所示
{
[
{
"WebCash" : {
"Id" : 1021,
"RedemptionCode" : "sdfkjk",
"PlayerCardId" : "3802",
"Amount" : 8000,
"Status" : 1,
"PurchaseTimeStamp" : 1445020270,
"RedeemTimeStamp" : 1445021971,
"RetailerId" : "1781",
"TerminalId" : "9",
}, {
"Id" : 1160,
"RedemptionCode" : "9123LKBJFDAXEK8194",
"PlayerCardId" : "3802",
"Amount" : 10000,
"Status" : 3,
"PurchaseTimeStamp" : 1445020270,
"RetailerId" : "1781",
"TerminalId" : "9",
}
}
]
}
當我們沒有不同的塊時,它可以正常工作,但是當我們的響應類型為{[{,,},{,,}]}時會拋出錯誤
我正在使用以下代碼
String Expected_Response = Response;
Dictionary<String, Object> ActualResponse_Dic = null;
ActualResponse_Dic = JsonConvert.DeserializeObject<Dictionary<String, Object>>(ResponseValue); //ResponseValue holds the entire Json response string
反序列化對象Path時,它將在最后一行意外的末尾引發錯誤。
我同意艾米提供的評論。 請嘗試以下操作:
也許像下面這樣:
[{
"WebCash": [{
"Id": 1021,
"RedemptionCode": "sdfkjk",
"PlayerCardId": "3802",
"Amount": 8000,
"Status": 1,
"PurchaseTimeStamp": 1445020270,
"RedeemTimeStamp": 1445021971,
"RetailerId": "1781",
"TerminalId": "9"
}, {
"Id": 1160,
"RedemptionCode": "9123LKBJFDAXEK8194",
"PlayerCardId": "3802",
"Amount": 10000,
"Status": 3,
"PurchaseTimeStamp": 1445020270,
"RetailerId": "1781",
"TerminalId": "9"
}]
}]
您的JSON無效。 此外, Dictionary <String,Object>可能會序列化為如下形式:
{
"WebCash" : {
"Id" : 1021,
"RedemptionCode" : "sdfkjk",
"PlayerCardId" : "3802",
"Amount" : 8000,
"Status" : 1,
"PurchaseTimeStamp" : 1445020270,
"RedeemTimeStamp" : 1445021971,
"RetailerId" : "1781",
"TerminalId" : "9"
},
"WebCash2" : {
"Id" : 1160,
"RedemptionCode" : "9123LKBJFDAXEK8194",
"PlayerCardId" : "3802",
"Amount" : 10000,
"Status" : 3,
"PurchaseTimeStamp" : 1445020270,
"RetailerId" : "1781",
"TerminalId" : "9"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.