2

I am consuming an HTTPWebResponse from a REST API that comes back as Base64 Encoded. When I decode it seems to Deserialise fine however when I create classes I have names that are invalid and have spaces in them.

I have tried JsonObject and JsonProperty but I don't seem to have the available references and name spaces in Visual Studio 2010 and SQL Server 2008 R2 (SSIS) and I cant figure out how to get past this.

It is a transaction detail file and as such is very large and cant be posted here. I am wondering if someone can point me to how to either load the right references to use the above methods or alternatively tell me how to read Json tags with spaces and still validly declare them in c# script component in SSIS.

EXAMPLE: RESPONSE:

            "High Risk Merchants": {
              "High Risk Merchants": [
                {
                  "AccountID": 4829640,
                  "H1": "High Risk Merchants",
                  "H2": "High Risk Merchants",
                  "H3": "",
                  "SH1": "",
                  "Description": "{NO MATCH}",
                  "Count": null,
                  "FrequencyDescription": null,
                  "FrequencyDuration": null,
                  "FrequencyDurationDate": null,
                  "FrequencyWeekday": null,
                  "FrequencyAmount": null,
                  "FrequencyAmountRange": null,
                  "TotalAmount": null,
                  "TotalInAmount": null,
                  "TotalOutAmount": null,
                  "MonthlyAmount": null,
                  "GroupID": null,
                  "Display": null,
                  "FrequencyExactness": null,
                  "FrequencyPeriod": null,
                  "ScoreEmployer": null,
                  "ScoreDirCr": null,
                  "ScoreWeekday": null,
                  "ScoreFrequency": null,
                  "ScoreAmount": null,
                  "ScoreTotal": null
                }
              ]
            },

EXAMPLE: C# Class declaration (json2csharp)

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 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 HighRiskMerchants
{
    public List<HighRiskMerchant> __invalid_name__High Risk Merchants { get; set; }
}

DATA Output Calls

 foreach (HighRiskMerchant hrm in ac.Overviews.Overview.HighRiskMerchants.HighRiskMerchantEntity)
            {
                RptOverviewDataBuffer.AddRow();
                RptOverviewDataBuffer.Type = "HighRiskMerchants";
                RptOverviewDataBuffer.SubType = "HighRiskMerchantsEntity";
                RptOverviewDataBuffer.AccountID = Convert.ToInt32(hrm.AccountID);
                RptOverviewDataBuffer.H1 = hrm.H1;
                RptOverviewDataBuffer.H2 = hrm.H2;
                RptOverviewDataBuffer.H3 = hrm.H3;
                RptOverviewDataBuffer.SH1 = hrm.SH1;
                RptOverviewDataBuffer.Description = hrm.Description;
                RptOverviewDataBuffer.Count = Convert.ToInt32(hrm.Count);
                RptOverviewDataBuffer.FrequencyDescription = hrm.FrequencyDescription;
                RptOverviewDataBuffer.FrequencyDuration = hrm.FrequencyDuration;
                RptOverviewDataBuffer.FrequencyDurationDate = hrm.FrequencyDurationDate;
                RptOverviewDataBuffer.FrequencyWeekday = hrm.FrequencyWeekday;
                RptOverviewDataBuffer.FrequencyAmount = Convert.ToDouble(hrm.FrequencyAmount);
                RptOverviewDataBuffer.FrequencyAmountRange = hrm.FrequencyAmountRange;
                RptOverviewDataBuffer.TotalAmount = Convert.ToDouble(hrm.TotalAmount);
                RptOverviewDataBuffer.TotalInAmount = Convert.ToDouble(hrm.TotalInAmount);
                RptOverviewDataBuffer.TotalOutAmount = Convert.ToDouble(hrm.TotalOutAmount);
                RptOverviewDataBuffer.MonthlyAmount = Convert.ToDouble(hrm.MonthlyAmount);
                RptOverviewDataBuffer.GroupID = hrm.GroupID;
                RptOverviewDataBuffer.Display = hrm.Display;
                RptOverviewDataBuffer.FrequencyExactness = hrm.FrequencyExactness;
                RptOverviewDataBuffer.FrequencyPeriod = hrm.FrequencyPeriod;
                RptOverviewDataBuffer.ScoreEmployer = Convert.ToInt32(hrm.ScoreEmployer);
                RptOverviewDataBuffer.ScoreDirCr = Convert.ToInt32(hrm.ScoreDirCr);
                RptOverviewDataBuffer.ScoreWeekday = hrm.ScoreWeekday;
                RptOverviewDataBuffer.ScoreFrequency = hrm.ScoreFrequency;
                RptOverviewDataBuffer.ScoreAmount = Convert.ToDouble(hrm.ScoreAmount);
                RptOverviewDataBuffer.ScoreTotal = Convert.ToInt32(hrm.ScoreTotal);
            }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lucas Perrett
  • 423
  • 1
  • 6
  • 16

1 Answers1

1

For the library to use, you can use nuget to install "Json.Net"

In this example, it would be:

public class HighRiskMerchants
{
    [JsonProperty(PropertyName = "High Risk Merchants")]
    public List<HighRiskMerchant> HighRiskMerchants { get; set; }
}
Community
  • 1
  • 1
spinalfrontier
  • 567
  • 1
  • 10
  • 20
  • How do I install NuGet Json.Net? I don't seem to have the options that your link shows. I am using Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel Microsoft .NET Framework Version 4.5.51209 SP1Rel – Lucas Perrett Apr 26 '17 at 23:23
  • First you need to install Nuget, then install Json.Net from there.Try this [link](http://peterkellner.net/2011/03/02/installing-nuget-on-vs2010-first-blood/) – spinalfrontier Apr 27 '17 at 01:26
  • I have tried this and it wont install a version that will allow me install Json.Net as I am restricted to VS 2010 SHELL. Theses are the errors I am getting here [link](http://stackoverflow.com/questions/43646661/nuget-json-net-install-erros-vs-2010-shell?noredirect=1#comment74341851_43646661) – Lucas Perrett Apr 27 '17 at 01:37
  • In that case you can do a direct [download](https://github.com/JamesNK/Newtonsoft.Json/releases) of the dll, then, under references in your project, add reference to this dll. – spinalfrontier Apr 27 '17 at 01:42
  • find Newtonsoft.Json.dll for your .net version – spinalfrontier Apr 27 '17 at 01:45
  • @spinalfronteir you are a legend! Thanks – Lucas Perrett Apr 27 '17 at 01:54