I am using a Web API that returns JSON. Within that JSON there is a base64 encoded JSON string that is returned.
The initial response returns JSON that uses the following classes.
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; }
}
The "content" in the Attachment
class is returned a base64-encoded JSON string.
Once decoded the JSON sting uses the following classes (this was generated from json2csharp.com)
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; }
}
With 2 "RootObjects" I need to know how to declare these?
Is there a way to do this? or is it best to output it and develop new Script?
Thanks in advance.
You can change the name of the Rootobject
for decoded json as
public class RootObjectDecoded
{
public Applications Applications { get; set; }
}
and while you want to deseralize it
var rr = JsonConvert.DeserializeObject<RootObjectDecoded>(yourdecodedjson);