|
Null and "something" is always null.
I would use the same philosophy here.
It's up to the "client" to make valid calls; the "server" just needs to keep from crashing.
Otherwise, use "type info" in the class. There is no "wrong" answer; only more or less coding.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Alexander Kindel wrote: The place where I really started to wish compile time type checking reflected the characteristic was not to constrain what a caller can do, but to check myself If you use over-ridden arithmetic operators, as shown in my first response to you, the parameter types of the arguments, and the specified return type, will effectively act as constraints.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
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:
private Card[] GetWebServiceResult(string wUrl)
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
Card[] jsonResponse = null;
try
{
if (httpWResp.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = httpWResp.GetResponseStream();
string jsonString = null;
using (StreamReader reader = new StreamReader(responseStream))
{
jsonString = reader.ReadToEnd().Replace("\\", "");
reader.Close();
}
JavaScriptSerializer sr = new JavaScriptSerializer();
jsonResponse = sr.Deserialize<Card[]>(jsonString);
}
else
{
FailComponent(httpWResp.StatusCode.ToString());
}
}
catch (Exception e)
{
FailComponent(e.ToString());
}
return jsonResponse;
}
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
|
|
|
|
|
If it doesn't work, go back to where you got the tutorial from, and ask there. If it's their code that doesn't work, it needs to be fixed. If it's that you haven't understood it, maybe they can improve the clarity.
But asking a random website that has nothing to do with the tutorial is just silly!
And ... you have to accept that most internet tutorials are pretty poor anyway: Don't Hit Save - Welcome To The Tutorial[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You know, calling CodeProject a "random website" might offend someone!
This site is filled with incredibly knowledgeable members, including yourself. This may be my first time posting, but I have scoured this site for years getting answers to many of my questions. It has an amazing community. I'm not choosing to post here by happenstance.
I'll agree that most tutorials are poorly written, but this one is not. It's actually far better than most. You are right that asking the original author makes sense, but the blog was written 5 years ago so expecting any response, let alone in a reasonable time frame is equally silly. Regardless, I've taken your suggestion and posted on his site linking to this one.
That said, my issue isn't with the content of the tutorial, but with my ability to debug the code "sr.Deserialize<card[]>(jsonString)". In the debug options, I've turned off "Enable Just My Code" and have the debugger loading all symbols, but I still can't actually see it deserialize so I don't know what's tripping up the program. If you can help with the debugger visibility then perhaps I can make some progress.
|
|
|
|
|
You need to "partition" your problem (better).
You're retrieving a string; deserializing it; etc.
You need to confirm what the actual contents of the string are. (Is it "formed" correctly?)
Then you attempt to deserialize just that string.
Visual Studio can generate classes from xml and json strings.
I KNOW that VS generates classes that work; I cannot speak for any other "tools".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks for your feedback, Gerry. I wasn't aware that VS could generate the JSON classes. That's awesome! I had to reinstall VS to get the VS paste special->Paste JSON as Classes to appear, but it the command works now.
I think I understand the root cause of my issues now, but I'm still not quite sure the best way to resolve it. I know you say that the VS generated classes work, but it's actually generating classes that don't compile. This is because there is a field called "name" and a field called "set_name", so "name" definition line fails with the following error:
"The type 'Datum' already contains a definition for 'set_name'". Please see the below code.
I did try getting around this by using [JsonProperty("name")] and capitalizing the field. It made it compile, but it's still failing when I run it.
Is there another way I can get around this in the class definition, or should I somehow figure out how to update the JSON string without messing with the rest of the data before attempting to deserialize it?
public class Datum
{
public string name { get; set; }
public string uri { get; set; }
public string set_name { get; set; }
public string set_uri { get; set; }
}
|
|
|
|
|
"set_name" is the "setter" being generated (by the compiler) as a result of "name" being defined as a property.
Stick with the attributes; just "rename" "set_name" or "name" or "both" ... I think you get the idea.
(You might get by by changing "name" to a public "field"; but it may not deserialize. Try it.)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 8-Apr-18 12:16pm.
|
|
|
|
|
Thanks Gerry.
It looks like I was using the property correctly.
The issue I was having was that I was trying to store the deserialized JSON into Card[] instead of just Card. That's why it kept failing for me.
I fixed that issue and everything magically started working. Thanks again for looking at it.
|
|
|
|
|
Hello,
I have a problem with the button hover effect, i dont want effects at all when i hover, i tryed so many things but nothing work.
I want to look like this when hover:
Like This
And not like this(I want to remove this effect):
Not Like This
Can anybody help?
Thank you all
|
|
|
|
|
You have to edit the button template to do that. That's a XAML problem, not a C# one.
This space for rent
|
|
|
|
|
.IsEnabled = false;
If not, you are violating common access conventions. This cannot be tolerated.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The entire flat button, no area segregation by colour violates common sense.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Or maybe it's just a really big button.
(It's what happens when you default to "Stretch").
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have three dropdownlists and the multiplication of the thse fropdown values is to be populated in this single textbox. Please help me how to use updatepanel in this situation. If I don't use update panel the autopostback event of the dropdownlist is very slow and takes over 40 seconds to respond.
appreciate all your help.
|
|
|
|
|
Can't you just do this "client-side"? Use a "calculate" button. And "script".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have the postback method doing it and is very slow, can you please send the client side of doing the same. I wanted to do it with Updatepanel, is there an easy way to do the same
|
|
|
|
|
Don't you know JavaScript (or whatever)? Isn't that's the way it's supposed to be? La la la.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
How do i create a windows form of a bouncing ball such that when the ball collides with an edge, its movement in the direction perpendicular to the edge should be inverted, while the movement in the direction parallel to the edge should remain unchanged.
There should be a numeric up-down control that controls the interval of the timer that controls the movement of the ball. The interval of the timer should be updated immediately when the value of this numeric up-down control is changed
|
|
|
|
|
|
i have created the windows form but the ball just bounces back and forth
'When the ball collides with an edge, its movement in the direction perpendicular to the edge should be inverted, while the movement in the direction parallel to the edge should remain unchanged.'
i also don't know how to create a code for the numeric up-down control so it can control the interval of the timer
and i have tried goggle i found nothing usefull
|
|
|
|
|
All that means is: when the ball hits an edge, it bounces off at the appropriate angle.
So if it hits the wall like this:
|
|
|
|
----->|
|
|
|
| It rebounds exactly as you'd expect:
|
|
|
|
<-----|
|
|
|
| It if hits at an angle, then it rebounds at an angle:
|
\ |
\ |
\ |
\|
|
|
|
|
Becomes
|
|
|
|
/|
/ |
/ |
/ |
|
Now, presumably, you have a "move this number X" and "move this number Y" values which you add to your ball coordinates each time the timer ticks? So just try inverting the "move number" for the appropriate direction: left and right walls modify dX = -dX, top and bottom modify dY = -dY
Make sense?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
yes it makes sense. i didn't think of that, thank you.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Member 13764451 wrote: How do i create a windows form of a bouncing ball such that when the ball collides with an edge, its movement in the direction perpendicular to the edge should be inverted, while the movement in the direction parallel to the edge should remain unchanged. Perpen.. cats?
You know how gravity works, yes? So, you could calculate a trajectory? Add some simple drawing-routines and you have a bouncy ball. It was one of the excercises in the AMOS Basic manual, where bouncing apples would fall from a tree. You can Google the code, but that won't translate easily to a modern C#.
Member 13764451 wrote: There should be a numeric up-down control that controls the interval of the timer that controls the movement of the ball. The interval of the timer should be updated immediately when the value of this numeric up-down control is changed You can do it! Good luck
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|