Click here to Skip to main content
15,887,436 members
Home / Discussions / C#
   

C#

 
AnswerRe: generic type with value parameter rather than type parameter Pin
BillWoodruff8-Apr-18 3:39
professionalBillWoodruff8-Apr-18 3:39 
AnswerRe: generic type with value parameter rather than type parameter Pin
#realJSOP8-Apr-18 5:36
mve#realJSOP8-Apr-18 5:36 
GeneralRe: generic type with value parameter rather than type parameter Pin
Alexander Kindel8-Apr-18 11:30
Alexander Kindel8-Apr-18 11:30 
AnswerRe: generic type with value parameter rather than type parameter Pin
Gerry Schmitz8-Apr-18 6:54
mveGerry Schmitz8-Apr-18 6:54 
GeneralRe: generic type with value parameter rather than type parameter Pin
Alexander Kindel8-Apr-18 11:18
Alexander Kindel8-Apr-18 11:18 
GeneralRe: generic type with value parameter rather than type parameter Pin
Gerry Schmitz8-Apr-18 12:00
mveGerry Schmitz8-Apr-18 12:00 
GeneralRe: generic type with value parameter rather than type parameter Pin
BillWoodruff9-Apr-18 11:47
professionalBillWoodruff9-Apr-18 11:47 
QuestionIssue Deserializing Json in C# SSIS Script Pin
rhutchins12346-Apr-18 14:27
rhutchins12346-Apr-18 14:27 
First time posting so please forgive me if I'm doing something wrong. I've read through the guidelines and have attempted many times to research this issue.

I'm attempting to use a C# script in SSIS to consume a JSON feed from a website. I found an amazing tutorial/blog which shows exactly what needs to be done. I've attempted to follow it step-by-step but the program keeps failing when it attempts to deserialize the JSON object. It fails with the below error message. Despite my best attempts, I can't figure out what I'm doing wrong, or if the JSON string has extra "stuff" that's messing with the deserialization. Any ideas?
Exception thrown: 'System.ArgumentException' in System.Web.Extensions.dll


JSON and SSIS Tutorial: Dennis and Jim's SSIS and BI Blog: Using a JSON Feed as a Data Source in SSIS[^]
Website JSON documentation: Card Objects · API Documentation · Scryfall Magic Card Search[^]
JSON Address: "https://api.scryfall.com/cards?"
JSON Class Generator: json2csharp - generate c# classes from json[^]

Code:
    /// <param name="wUrl">The web service URL to call</param>
    /// <returns>An array of Card composed of the de-serialized JSON</returns>
    private Card[] GetWebServiceResult(string wUrl)
    {
        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
        HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
        Card[] jsonResponse = null;

        try
        {
            //Test the connection
            if (httpWResp.StatusCode == HttpStatusCode.OK)
            {

                Stream responseStream = httpWResp.GetResponseStream();
                string jsonString = null;

                //Set jsonString using a stream reader
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    jsonString = reader.ReadToEnd().Replace("\\", "");
                    reader.Close();
                }

                //Deserialize our JSON
                JavaScriptSerializer sr = new JavaScriptSerializer();
                
                /*CODE FAILS HERE*/
                jsonResponse = sr.Deserialize<Card[]>(jsonString);

            }
            //Output connection error message
            else
            {
                FailComponent(httpWResp.StatusCode.ToString());

            }
        }
        //Output JSON parsing error
        catch (Exception e)
        {
            FailComponent(e.ToString());
        }
        return jsonResponse;

    }

    /// <summary>
    /// Outputs error message
    /// </summary>
    /// <param name="errorMsg">Full error text</param>
    private void FailComponent(string errorMsg)
    {
        bool fail = false;
        IDTSComponentMetaData100 compMetadata = this.ComponentMetaData;
        compMetadata.FireError(1, "Error Getting Data From Webservice!", errorMsg, "", 0, out fail);

    }

}
#endregion

#region JSON Class

public class ImageUris
{
    public string small { get; set; }
    public string normal { get; set; }
    public string large { get; set; }
    public string png { get; set; }
    public string art_crop { get; set; }
    public string border_crop { get; set; }
}

public class Legalities
{
    public string standard { get; set; }
    public string future { get; set; }
    public string frontier { get; set; }
    public string modern { get; set; }
    public string legacy { get; set; }
    public string pauper { get; set; }
    public string vintage { get; set; }
    public string penny { get; set; }
    public string commander { get; set; }
    public string __invalid_name__1v1 { get; set; }
    public string duel { get; set; }
    public string brawl { get; set; }
}

public class RelatedUris
{
    public string tcgplayer_decks { get; set; }
    public string edhrec { get; set; }
    public string mtgtop8 { get; set; }
}

public class PurchaseUris
{
    public string amazon { get; set; }
    public string ebay { get; set; }
    public string tcgplayer { get; set; }
    public string magiccardmarket { get; set; }
    public string cardhoarder { get; set; }
    public string card_kingdom { get; set; }
    public string mtgo_traders { get; set; }
    public string coolstuffinc { get; set; }
}

public class AllPart
{
    public string @object { get; set; }
    public string id { get; set; }
    public string name { get; set; }
    public string uri { get; set; }
}

public class Datum
{
    public string @object { get; set; }
    public string id { get; set; }
    public string oracle_id { get; set; }
    public List<object> multiverse_ids { get; set; }
    [JsonProperty("name")]
    public string Name { get; set; }
    [JsonProperty("uri")]
    public string Uri { get; set; }
    public string scryfall_uri { get; set; }
    public string layout { get; set; }
    public bool highres_image { get; set; }
    public ImageUris image_uris { get; set; }
    public double cmc { get; set; }
    public string type_line { get; set; }
    public string oracle_text { get; set; }
    public string mana_cost { get; set; }
    public string loyalty { get; set; }
    public List<object> colors { get; set; }
    public List<object> color_identity { get; set; }
    public Legalities legalities { get; set; }
    public bool reserved { get; set; }
    public bool reprint { get; set; }
    public string set { get; set; }
    public string set_name { get; set; }
    public string set_uri { get; set; }
    public string set_search_uri { get; set; }
    public string scryfall_set_uri { get; set; }
    public string rulings_uri { get; set; }
    public string prints_search_uri { get; set; }
    public string collector_number { get; set; }
    public bool digital { get; set; }
    public string rarity { get; set; }
    public string illustration_id { get; set; }
    public string artist { get; set; }
    public string frame { get; set; }
    public bool full_art { get; set; }
    public string border_color { get; set; }
    public bool timeshifted { get; set; }
    public bool colorshifted { get; set; }
    public bool futureshifted { get; set; }
    public int edhrec_rank { get; set; }
    public RelatedUris related_uris { get; set; }
    public PurchaseUris purchase_uris { get; set; }
    public string flavor_text { get; set; }
    public string usd { get; set; }
    public int? story_spotlight_number { get; set; }
    public string power { get; set; }
    public string toughness { get; set; }
    public List<AllPart> all_parts { get; set; }
    public string eur { get; set; }
    public string watermark { get; set; }
}

public class Card
{
    public string @object { get; set; }
    public int total_cards { get; set; }
    public bool has_more { get; set; }
    public string next_page { get; set; }
    public List<Datum> data { get; set; }
}

#endregion

AnswerRe: Issue Deserializing Json in C# SSIS Script Pin
OriginalGriff6-Apr-18 21:09
mveOriginalGriff6-Apr-18 21:09 
GeneralRe: Issue Deserializing Json in C# SSIS Script Pin
rhutchins12347-Apr-18 3:01
rhutchins12347-Apr-18 3:01 
AnswerRe: Issue Deserializing Json in C# SSIS Script Pin
Gerry Schmitz7-Apr-18 6:51
mveGerry Schmitz7-Apr-18 6:51 
GeneralRe: Issue Deserializing Json in C# SSIS Script Pin
rhutchins12347-Apr-18 16:37
rhutchins12347-Apr-18 16:37 
GeneralRe: Issue Deserializing Json in C# SSIS Script Pin
Gerry Schmitz8-Apr-18 6:06
mveGerry Schmitz8-Apr-18 6:06 
GeneralRe: Issue Deserializing Json in C# SSIS Script Pin
rhutchins123414-Apr-18 11:05
rhutchins123414-Apr-18 11:05 
QuestionButton hover problem C# Visual Studio UWP Pin
Member 137658766-Apr-18 1:55
Member 137658766-Apr-18 1:55 
AnswerRe: Button hover problem C# Visual Studio UWP Pin
Pete O'Hanlon6-Apr-18 2:18
mvePete O'Hanlon6-Apr-18 2:18 
AnswerRe: Button hover problem C# Visual Studio UWP Pin
Gerry Schmitz6-Apr-18 7:40
mveGerry Schmitz6-Apr-18 7:40 
RantRe: Button hover problem C# Visual Studio UWP Pin
Mycroft Holmes6-Apr-18 13:10
professionalMycroft Holmes6-Apr-18 13:10 
GeneralRe: Button hover problem C# Visual Studio UWP Pin
Gerry Schmitz6-Apr-18 13:44
mveGerry Schmitz6-Apr-18 13:44 
Questionupdatepanel usage with three dropdownlists values into a single textbox Pin
chetan265-Apr-18 9:50
chetan265-Apr-18 9:50 
AnswerRe: updatepanel usage with three dropdownlists values into a single textbox Pin
Gerry Schmitz5-Apr-18 17:20
mveGerry Schmitz5-Apr-18 17:20 
GeneralRe: updatepanel usage with three dropdownlists values into a single textbox Pin
chetan266-Apr-18 3:36
chetan266-Apr-18 3:36 
GeneralRe: updatepanel usage with three dropdownlists values into a single textbox Pin
Gerry Schmitz6-Apr-18 7:34
mveGerry Schmitz6-Apr-18 7:34 
QuestionHow do i to create a bouncing ball in C# Pin
Member 137644515-Apr-18 5:15
Member 137644515-Apr-18 5:15 
AnswerRe: How do i to create a bouncing ball in C# Pin
OriginalGriff5-Apr-18 5:21
mveOriginalGriff5-Apr-18 5:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.