Как десериализовать сложный объект JSON с помощью c #, пожалуйста, мне нужно
Десериализуйте строку JSON в следующем? я пытался поставить
свойство транзакции в качестве словаря и не работает, поэтому, пожалуйста, любой
идея?
Исключение при замене транзакции из массива в словарь: невозможно сериализовать член wsA2AEBS.WCTransactionsResponse1.transactions
типа System.Collections.Generic.Dictionary`2 [[System.String,
mscorlib, версия = 4.0.0.0, культура = нейтральная,
PublicKeyToken = b77a5c561934e089], [wsA2AEBS.WCTransInfoRes, wsA2AEBS,
Версия = 1.0.0.0, Культура = нейтральная, PublicKeyToken = null]], потому что это
реализует IDictionary. Описание: произошло необработанное исключение
во время выполнения текущего веб-запроса. Пожалуйста, просмотрите
трассировка стека для получения дополнительной информации об ошибке и где она
возник в коде.
Сведения об исключении: System.NotSupportedException: невозможно сериализовать
член wsA2AEBS.WCTransactionsResponse1.transactions типа
System.Collections.Generic.Dictionary`2 [[System.String, mscorlib,
Версия = 4.0.0.0, Культура = нейтральная,
PublicKeyToken = b77a5c561934e089], [wsA2AEBS.WCTransInfoRes, wsA2AEBS,
Версия = 1.0.0.0, Культура = нейтральная, PublicKeyToken = null]], потому что это
реализует IDictionary.
---------- JSON-файл
{
""applicationId"": ""ONB"",
""tranDateTime"": ""300817114023"",
""UUID"": ""e8289a8e-b522-4c56-b6df-d15b8cecb5d6"",
""responseStatus"": ""Successful"",
""responseCode"": 1,
""responseMessage"": ""Approved"",
""consumerIdentifier"": ""249915513503"",
""isConsumer"": true,
""fee"": 0.0,
""transactions"": {
""750271185417"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""750724170249"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""752569664009"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""750774501897"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""752401891849"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""753475633673"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_BALANCE"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""702396401949"": {
""amount"": ""1.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": ""249915513503"",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0"",
""type"": ""CASH_IN"",
""sourceIdentifier"": ""313827219935"",
""transactionName"": """"
},
""751328150025"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""753391747593"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_TRANSACTIONS"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
},
""750422180361"": {
""amount"": ""0.00"",
""fee"": ""0"",
""customerPayeeId"": """",
""destinationIdentifier"": """",
""status"": ""COMPLETED"",
""payeeId"": """",
""billId"": """",
""externalFee"": ""0.00"",
""type"": ""GET_BALANCE"",
""sourceIdentifier"": ""300136232415"",
""transactionName"": """"
}
},
""transactionId"": ""754046059017""
}
---------- Классы
public class WCTransactionsResponse
{
public string applicationId;
public string tranDateTime;
public string UUID;
public string consumerIdentifier;
public bool isConsumer;
public string extraData;
//public string notifyConsumer;
//public string tranFeeAmount;
//public string feeSource;
//public string feeShare;
public string responseStatus;
public string responseCode;
public string responseMessage;
public string fee;
public WCTransInfoRes[] transactions;
public string transactionId;
}
public class WCTransInfoRes
{
public string status;
public string type;
public string amount;
public string fee;
public string externalFee;
public string sourceIdentifier;
public string destinationIdentifier;
public string billId;
public string payeeId;
public string customerPayeeId;
public string transactionName;
}
---------- Преобразовать строку Json
WCTransactionsResponse Resp = new WCTransactionsResponse();
var json = File.ReadAllText(@"E:\wsA2AEBS\wsA2AEBS\json.json");
//var jObject = JObject.Parse(json);
Resp = JsonConvert.DeserializeObject<WCTransactionsResponse>(json);
return Resp;// jObject.ToString();