2016-11-30 6 views
1

Ich verwende eine Web-API, die JSON zurückgibt. Innerhalb dieses JSON gibt es eine Base64-codierte JSON-Zeichenfolge, die zurückgegeben wird.Geschachtelte JSON-Deserialisierung in C# SSIS

Die erste Antwort gibt JSON zurück, das die folgenden Klassen verwendet.

public class Attachment 
{ 
    public string type { get; set; } 
    public string name { get; set; } 
    public string contentType { get; set; } 
    public string content { get; set; } 
} 

public class Response 
{ 
    public int postVersion { get; set; } 
    public int appId { get; set; } 
    public string appReference { get; set; } 
    public string createDate { get; set; } 
    public string clientName { get; set; } 
    public string storeName { get; set; } 
    public List<Attachment> attachments { get; set; } 
} 

public class RootObject 
{ 
    public bool Success { get; set; } 
    public Response Response { get; set; } 
} 

der "Inhalt" in der Attachment Klasse ist eine Base64-kodiert JSON Zeichenkette zurückgegeben.

Sobald die JSON Stachel decodiert die folgenden Klassen verwendet (dies aus json2csharp.com generiert wurde)

public class Salary 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public object Count { get; set; } 
    public object FrequencyDescription { get; set; } 
    public object FrequencyDuration { get; set; } 
    public object FrequencyDurationDate { get; set; } 
    public object FrequencyWeekday { get; set; } 
    public object FrequencyAmount { get; set; } 
    public object FrequencyAmountRange { get; set; } 
    public object TotalAmount { get; set; } 
    public object TotalInAmount { get; set; } 
    public object TotalOutAmount { get; set; } 
    public object MonthlyAmount { get; set; } 
    public object GroupID { get; set; } 
    public object Display { get; set; } 
    public object FrequencyExactness { get; set; } 
    public object FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public object ScoreTotal { get; set; } 
} 

public class Benefit 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public object Count { get; set; } 
    public object FrequencyDescription { get; set; } 
    public object FrequencyDuration { get; set; } 
    public object FrequencyDurationDate { get; set; } 
    public object FrequencyWeekday { get; set; } 
    public object FrequencyAmount { get; set; } 
    public object FrequencyAmountRange { get; set; } 
    public object TotalAmount { get; set; } 
    public object TotalInAmount { get; set; } 
    public object TotalOutAmount { get; set; } 
    public object MonthlyAmount { get; set; } 
    public object GroupID { get; set; } 
    public object Display { get; set; } 
    public object FrequencyExactness { get; set; } 
    public object FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public object ScoreTotal { get; set; } 
} 

public class OtherIncome 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double TotalAmount { get; set; } 
    public double TotalInAmount { get; set; } 
    public int TotalOutAmount { get; set; } 
    public int MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int ScoreTotal { get; set; } 
} 

public class Income 
{ 
    public List<Salary> Salary { get; set; } 
    public List<Benefit> Benefits { get; set; } 
    public List<OtherIncome> __invalid_name__Other Income { get; set; } 
} 

public class SmallAmountLoan 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int? Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public int? FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public int? TotalAmount { get; set; } 
    public int? TotalInAmount { get; set; } 
    public int? TotalOutAmount { get; set; } 
    public int? MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int? ScoreTotal { get; set; } 
} 

public class SmallAmountRepayment 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double TotalAmount { get; set; } 
    public int TotalInAmount { get; set; } 
    public double TotalOutAmount { get; set; } 
    public double MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int ScoreTotal { get; set; } 
} 

public class OtherLoan 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public object Count { get; set; } 
    public object FrequencyDescription { get; set; } 
    public object FrequencyDuration { get; set; } 
    public object FrequencyDurationDate { get; set; } 
    public object FrequencyWeekday { get; set; } 
    public object FrequencyAmount { get; set; } 
    public object FrequencyAmountRange { get; set; } 
    public object TotalAmount { get; set; } 
    public object TotalInAmount { get; set; } 
    public object TotalOutAmount { get; set; } 
    public object MonthlyAmount { get; set; } 
    public object GroupID { get; set; } 
    public object Display { get; set; } 
    public object FrequencyExactness { get; set; } 
    public object FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public object ScoreTotal { get; set; } 
} 

public class OtherRepayment 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public object Count { get; set; } 
    public object FrequencyDescription { get; set; } 
    public object FrequencyDuration { get; set; } 
    public object FrequencyDurationDate { get; set; } 
    public object FrequencyWeekday { get; set; } 
    public object FrequencyAmount { get; set; } 
    public object FrequencyAmountRange { get; set; } 
    public object TotalAmount { get; set; } 
    public object TotalInAmount { get; set; } 
    public object TotalOutAmount { get; set; } 
    public object MonthlyAmount { get; set; } 
    public object GroupID { get; set; } 
    public object Display { get; set; } 
    public object FrequencyExactness { get; set; } 
    public object FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public object ScoreTotal { get; set; } 
} 

public class Loans 
{ 
    public List<SmallAmountLoan> __invalid_name__Small Amount Loans { get; set; } 
    public List<SmallAmountRepayment> __invalid_name__Small Amount Repayments { get; set; } 
    public List<OtherLoan> __invalid_name__Other Loans { get; set; } 
    public List<OtherRepayment> __invalid_name__Other Repayments { get; set; } 
} 

public class Dishonour 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int? Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double? FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double? TotalAmount { get; set; } 
    public double? TotalInAmount { get; set; } 
    public int? TotalOutAmount { get; set; } 
    public double? MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int? ScoreTotal { get; set; } 
} 

public class Dishonours 
{ 
    public List<Dishonour> Dishonours { get; set; } 
} 

public class HighRiskMerchant 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public object Count { get; set; } 
    public object FrequencyDescription { get; set; } 
    public object FrequencyDuration { get; set; } 
    public object FrequencyDurationDate { get; set; } 
    public object FrequencyWeekday { get; set; } 
    public object FrequencyAmount { get; set; } 
    public object FrequencyAmountRange { get; set; } 
    public object TotalAmount { get; set; } 
    public object TotalInAmount { get; set; } 
    public object TotalOutAmount { get; set; } 
    public object MonthlyAmount { get; set; } 
    public object GroupID { get; set; } 
    public object Display { get; set; } 
    public object FrequencyExactness { get; set; } 
    public object FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public object ScoreTotal { get; set; } 
} 

public class HighRiskMerchants 
{ 
    public List<HighRiskMerchant> __invalid_name__High Risk Merchants { get; set; } 
} 

public class Rent 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int? Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public int? FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public int? TotalAmount { get; set; } 
    public int? TotalInAmount { get; set; } 
    public int? TotalOutAmount { get; set; } 
    public int? MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int? ScoreTotal { get; set; } 
} 

public class Periodic 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int? Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double? FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double? TotalAmount { get; set; } 
    public int? TotalInAmount { get; set; } 
    public double? TotalOutAmount { get; set; } 
    public double? MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int? ScoreTotal { get; set; } 
} 

public class NonPeriodic 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double TotalAmount { get; set; } 
    public int TotalInAmount { get; set; } 
    public double TotalOutAmount { get; set; } 
    public int MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int ScoreTotal { get; set; } 
} 

public class TopUncommittedSpend 
{ 
    public int AccountID { get; set; } 
    public string H1 { get; set; } 
    public string H2 { get; set; } 
    public string H3 { get; set; } 
    public string SH1 { get; set; } 
    public string Description { get; set; } 
    public int? Count { get; set; } 
    public string FrequencyDescription { get; set; } 
    public string FrequencyDuration { get; set; } 
    public string FrequencyDurationDate { get; set; } 
    public string FrequencyWeekday { get; set; } 
    public double? FrequencyAmount { get; set; } 
    public string FrequencyAmountRange { get; set; } 
    public double? TotalAmount { get; set; } 
    public double? TotalInAmount { get; set; } 
    public int? TotalOutAmount { get; set; } 
    public int? MonthlyAmount { get; set; } 
    public string GroupID { get; set; } 
    public string Display { get; set; } 
    public string FrequencyExactness { get; set; } 
    public string FrequencyPeriod { get; set; } 
    public object ScoreEmployer { get; set; } 
    public object ScoreDirCr { get; set; } 
    public object ScoreWeekday { get; set; } 
    public object ScoreFrequency { get; set; } 
    public object ScoreAmount { get; set; } 
    public int? ScoreTotal { get; set; } 
} 

public class Liabilities 
{ 
    public List<Rent> Rent { get; set; } 
    public List<Periodic> Periodic { get; set; } 
    public List<NonPeriodic> __invalid_name__Non-Periodic { get; set; } 
    public List<TopUncommittedSpend> __invalid_name__Top Uncommitted Spend { get; set; } 
} 

public class Overview 
{ 
    public Income Income { get; set; } 
    public Loans Loans { get; set; } 
    public Dishonours Dishonours { get; set; } 
    public HighRiskMerchants __invalid_name__High Risk Merchants { get; set; } 
    public Liabilities Liabilities { get; set; } 
} 

public class Overviews 
{ 
    public Overview Overview { get; set; } 
} 

public class Transaction 
{ 
    public int AccountID { get; set; } 
    public object TranID { get; set; } 
    public string CleanDesc { get; set; } 
    public string Category { get; set; } 
    public object TranDate { get; set; } 
    public object TranAmount { get; set; } 
    public object TranBaseTypeID { get; set; } 
    public string TranBaseType { get; set; } 
    public string GroupID { get; set; } 
    public double Balance { get; set; } 
} 

public class Transactions 
{ 
    public List<Transaction> Transaction { get; set; } 
} 

public class Account 
{ 
    public int AccountID { get; set; } 
    public string AccountNumber { get; set; } 
    public string AccountType { get; set; } 
    public string AccountName { get; set; } 
    public string AccountHolder { get; set; } 
    public string SecondaryAccountHolder { get; set; } 
    public double BankAvailableBalance { get; set; } 
    public double BankCurrentBalanceOriginal { get; set; } 
    public double BankCurrentBalance { get; set; } 
    public object CardMinPayment { get; set; } 
    public object CardRunningBalance { get; set; } 
    public object CardLastPaymentAmount { get; set; } 
    public object CardAvailableCredit { get; set; } 
    public object CardTotalCreditLine { get; set; } 
    public object CardDueDate { get; set; } 
    public object CardLastPaymentDate { get; set; } 
    public string CreateDT { get; set; } 
    public int ServiceID { get; set; } 
    public string BankName { get; set; } 
    public string AccountBSB { get; set; } 
    public int DishonourCount { get; set; } 
    public int DaysRange { get; set; } 
    public object accountCategoryId { get; set; } 
    public object accountCategory { get; set; } 
    public object loanInterestRateTypeId { get; set; } 
    public object loanInterestRateType { get; set; } 
    public object loanTerm { get; set; } 
    public object loanTypeId { get; set; } 
    public object loanType { get; set; } 
    public object interestRate { get; set; } 
    public object dueDateLoan { get; set; } 
    public object overDraft { get; set; } 
    public object lastPaymentDate { get; set; } 
    public double MaxAmountOverdraft { get; set; } 
    public int DaysOverdraft { get; set; } 
    public double TotalCredits { get; set; } 
    public double TotalDebits { get; set; } 
    public string FirstTransaction { get; set; } 
    public string LastTransaction { get; set; } 
    public double DayAgoBalance { get; set; } 
    public Overviews Overviews { get; set; } 
    public Transactions Transactions { get; set; } 
} 

public class Accounts 
{ 
    public List<Account> Account { get; set; } 
} 

public class DecisionPoint 
{ 
    public int CriteriaID { get; set; } 
    public int ReportID { get; set; } 
    public string Criteria { get; set; } 
    public string CriteriaName { get; set; } 
    public string Score { get; set; } 
    public object ScoreDT { get; set; } 
    public int CriteriaTypeID { get; set; } 
} 

public class DecisionPoints 
{ 
    public List<DecisionPoint> DecisionPoint { get; set; } 
} 

public class Application 
{ 
    public int AppID { get; set; } 
    public int ReportID { get; set; } 
    public string AppReference { get; set; } 
    public string CreateDT { get; set; } 
    public string ClientName { get; set; } 
    public string StoreName { get; set; } 
    public string Email { get; set; } 
    public string StoreCode { get; set; } 
    public string AppShortReference { get; set; } 
    public string ClientNameShort { get; set; } 
    public string StoreNameShort { get; set; } 
    public object VerifyEmployer { get; set; } 
    public object VerifyAmount { get; set; } 
    public object VerifyFrequency { get; set; } 
    public object VerifyWeekday { get; set; } 
    public string LocalityCode { get; set; } 
    public int TemplateReportID { get; set; } 
    public int daysRange { get; set; } 
    public string templateReportName { get; set; } 
    public Accounts Accounts { get; set; } 
    public DecisionPoints DecisionPoints { get; set; } 
} 

public class Applications 
{ 
    public Application Application { get; set; } 
} 

public class RootObject 
{ 
    public Applications Applications { get; set; } 
} 

Mit 2 „RootObjects“ Ich muss wissen, wie diese erklären?

Gibt es eine Möglichkeit, dies zu tun? oder ist es am besten, es auszugeben und neues Script zu entwickeln?

Vielen Dank im Voraus.

+0

kann u zeigen deseralize wollen, wie ur * Base64-codierte JSON-String * und * decodiert json string * sieht aus wie ?? –

+0

Dies ist die erste Antwort. der "Inhalt" die codierte JSON –

+0

{ "Erfolg": true, "Response": { "postVersion": 2, "appId": 2.891.426, "appReference": „Taplin 12-Oct-16 10 : 37: 02.00“ "Createdate": "2016.10.12 10: 36: 59,8900000" "client": "GoGetta Brisbane" "storename": "Handlers" "Anlagen": [ { "type": "Credit Sense Report", "name": "Enhanced Income Verbindlichkeiten Full Report", "content": "json", "content": "eyJBcHBsaWNhdGlvbnMiOnsiQXBwbGljYXRpb24iOnsiQXBwSUQiOjI4OTE0MjYsIlJlcG9ydElEIjo0 ..." } ] } } ' –

Antwort

0

Sie können den Namen des Rootobject für decodierte json als

public class RootObjectDecoded 
{ 
    public Applications Applications { get; set; } 
} 

ändern und während Sie es

var rr = JsonConvert.DeserializeObject<RootObjectDecoded>(yourdecodedjson); 
+0

Danke! kann ich dasselbe mit den ungültigen Namen tun, die Leerzeichen in ihnen haben? und json2sharp hat sie als ungültig bezeichnet? 'öffentliche Klasse Verbindlichkeiten { öffentliche Liste Rent {get; einstellen; } öffentliche Liste Periodisch {get; einstellen; } öffentliche Liste __invalid_name__Non-Periodic {get; einstellen; } öffentliche Liste __invalid_name__Top Uncommitted Ausgaben {get; einstellen; } } ' –

+0

Ich bin nicht sicher, über welche Namen Sie sprechen, aber Sie können keine Leerzeichen im Klassennamen haben. Das ist sicherlich ein ungültiger Name. –

+0

Ja, ich weiß, dass es ein ungültiger Klassenname ist, aber wenn ich ihn in einen gültigen Namen ändere, wird er korrekt deserialisiert? –

Verwandte Themen