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);
            }
3
  • Share your JSON Response and the classes. Commented Apr 26, 2017 at 4:56
  • As I have stated this is too large and exceeds the limity but I have added example Commented Apr 26, 2017 at 5:05
  • You don't need to post full json, just an image of how your json looks like and your classes as well. Commented Apr 26, 2017 at 5:07

1 Answer 1

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; }
}
Sign up to request clarification or add additional context in comments.

6 Comments

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
First you need to install Nuget, then install Json.Net from there.Try this link
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
In that case you can do a direct download of the dll, then, under references in your project, add reference to this dll.
find Newtonsoft.Json.dll for your .net version
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.