Deserializing Json Response to a Dictionary<string, object> throws error : unexpected end when deserializing object
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
它在最后一行抛出错误
反序列化对象路径时意外结束....
我同意 Amy 提供的评论。请尝试以下操作:
- 移除最外面的大括号{}
- 去掉"TerminalId"后面的逗号:“9”
- 将 "WebCash" 个对象放在方括号 [] 周围:
可能像下面这样:
[{
"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"
}
}
您好,我正在尝试反序列化 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
它在最后一行抛出错误 反序列化对象路径时意外结束....
我同意 Amy 提供的评论。请尝试以下操作:
- 移除最外面的大括号{}
- 去掉"TerminalId"后面的逗号:“9”
- 将 "WebCash" 个对象放在方括号 [] 周围:
可能像下面这样:
[{
"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"
}
}