Json Api values 0 or false2019 Community Moderator Electionparse json response c#How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How to parse JSON in JavaWhy does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?
Possible to detect presence of nuclear bomb?
Signed and unsigned numbers
Can we track matter through time by looking at different depths in space?
Why couldn't the separatists legally leave the Republic?
What will happen if my luggage gets delayed?
Why restrict private health insurance?
Should I take out a loan for a friend to invest on my behalf?
Professor forcing me to attend a conference, I can't afford even with 50% funding
Is it possible to avoid unpacking when merging Association?
Plausibility of Mushroom Buildings
How to design an organic heat-shield?
Why is a very small peak with larger m/z not considered to be the molecular ion?
What is this diamond of every day?
Outlet with 3 sets of wires
Are all players supposed to be able to see each others' character sheets?
What is the generally accepted pronunciation of “topoi”?
MySQL importing CSV files really slow
I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?
Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?
Why does Solve lock up when trying to solve the quadratic equation with large integers?
Doubts in understanding some concepts of potential energy
Why is there an extra space when I type "ls" in the Desktop directory?
Recommendation letter by significant other if you worked with them professionally?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
Json Api values 0 or false
2019 Community Moderator Electionparse json response c#How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How to parse JSON in JavaWhy does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?
I am using a web JSON api to provide some values from a game market into c# objects. I am fairly new to c# and haven't worked with API's before.
Heres my code:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Buy
public static ForQuery forQuery get; set;
public static long volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class ForQuery2
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public static int volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
JToken.Parse(sLine.Replace("[", "").Replace("]", "")).ToObject<RootObject>();
Console.WriteLine(Buy.max);
Console.WriteLine(Buy.highToLow);
Console.ReadLine();
and the web api JSON outputs this:
[
"buy":
"forQuery":
"bid": true,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 5544790080,
"wavg": 11.43,
"avg": 10.86,
"variance": 4.38,
"stdDev": 2.09,
"median": 12,
"fivePercent": 13.75,
"max": 20,
"min": 5,
"highToLow": true,
"generated": 1551926105235
,
"sell":
"forQuery":
"bid": false,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 258207299,
"wavg": 16.8,
"avg": 20.21,
"variance": 132.71,
"stdDev": 11.52,
"median": 15.99,
"fivePercent": 12.92,
"max": 60,
"min": 6,
"highToLow": false,
"generated": 1551926105235
]
I am not sure why Console.WriteLine(Buy.max); shows as 0 instead of 20 and Console.WriteLine(Buy.highToLow); shows as false instead of true. what am I doing wrong? I have looked for solutions to this issue for the past few hours to no avail. Any help would be greatly appreciated!
c# json parsing console-application
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I am using a web JSON api to provide some values from a game market into c# objects. I am fairly new to c# and haven't worked with API's before.
Heres my code:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Buy
public static ForQuery forQuery get; set;
public static long volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class ForQuery2
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public static int volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
JToken.Parse(sLine.Replace("[", "").Replace("]", "")).ToObject<RootObject>();
Console.WriteLine(Buy.max);
Console.WriteLine(Buy.highToLow);
Console.ReadLine();
and the web api JSON outputs this:
[
"buy":
"forQuery":
"bid": true,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 5544790080,
"wavg": 11.43,
"avg": 10.86,
"variance": 4.38,
"stdDev": 2.09,
"median": 12,
"fivePercent": 13.75,
"max": 20,
"min": 5,
"highToLow": true,
"generated": 1551926105235
,
"sell":
"forQuery":
"bid": false,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 258207299,
"wavg": 16.8,
"avg": 20.21,
"variance": 132.71,
"stdDev": 11.52,
"median": 15.99,
"fivePercent": 12.92,
"max": 60,
"min": 6,
"highToLow": false,
"generated": 1551926105235
]
I am not sure why Console.WriteLine(Buy.max); shows as 0 instead of 20 and Console.WriteLine(Buy.highToLow); shows as false instead of true. what am I doing wrong? I have looked for solutions to this issue for the past few hours to no avail. Any help would be greatly appreciated!
c# json parsing console-application
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
1
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. YourBuyandSellclasses are identical, so is theForQueryclass. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.
– Jimi
Mar 7 at 5:07
Also, you can use an attribute[JsonProperty("[OriginalPropertyName]")]if you need to change the name of a property.
– Jimi
Mar 7 at 5:13
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32
add a comment |
I am using a web JSON api to provide some values from a game market into c# objects. I am fairly new to c# and haven't worked with API's before.
Heres my code:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Buy
public static ForQuery forQuery get; set;
public static long volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class ForQuery2
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public static int volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
JToken.Parse(sLine.Replace("[", "").Replace("]", "")).ToObject<RootObject>();
Console.WriteLine(Buy.max);
Console.WriteLine(Buy.highToLow);
Console.ReadLine();
and the web api JSON outputs this:
[
"buy":
"forQuery":
"bid": true,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 5544790080,
"wavg": 11.43,
"avg": 10.86,
"variance": 4.38,
"stdDev": 2.09,
"median": 12,
"fivePercent": 13.75,
"max": 20,
"min": 5,
"highToLow": true,
"generated": 1551926105235
,
"sell":
"forQuery":
"bid": false,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 258207299,
"wavg": 16.8,
"avg": 20.21,
"variance": 132.71,
"stdDev": 11.52,
"median": 15.99,
"fivePercent": 12.92,
"max": 60,
"min": 6,
"highToLow": false,
"generated": 1551926105235
]
I am not sure why Console.WriteLine(Buy.max); shows as 0 instead of 20 and Console.WriteLine(Buy.highToLow); shows as false instead of true. what am I doing wrong? I have looked for solutions to this issue for the past few hours to no avail. Any help would be greatly appreciated!
c# json parsing console-application
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am using a web JSON api to provide some values from a game market into c# objects. I am fairly new to c# and haven't worked with API's before.
Heres my code:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Buy
public static ForQuery forQuery get; set;
public static long volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class ForQuery2
public static bool bid get; set;
public static List<int> types get; set;
public static List<object> regions get; set;
public static List<object> systems get; set;
public static int hours get; set;
public static int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public static int volume get; set;
public static double wavg get; set;
public static double avg get; set;
public static double variance get; set;
public static double stdDev get; set;
public static double median get; set;
public static double fivePercent get; set;
public static double max get; set;
public static double min get; set;
public static bool highToLow get; set;
public static long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
JToken.Parse(sLine.Replace("[", "").Replace("]", "")).ToObject<RootObject>();
Console.WriteLine(Buy.max);
Console.WriteLine(Buy.highToLow);
Console.ReadLine();
and the web api JSON outputs this:
[
"buy":
"forQuery":
"bid": true,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 5544790080,
"wavg": 11.43,
"avg": 10.86,
"variance": 4.38,
"stdDev": 2.09,
"median": 12,
"fivePercent": 13.75,
"max": 20,
"min": 5,
"highToLow": true,
"generated": 1551926105235
,
"sell":
"forQuery":
"bid": false,
"types": [
1230
],
"regions": [],
"systems": [],
"hours": 24,
"minq": 1
,
"volume": 258207299,
"wavg": 16.8,
"avg": 20.21,
"variance": 132.71,
"stdDev": 11.52,
"median": 15.99,
"fivePercent": 12.92,
"max": 60,
"min": 6,
"highToLow": false,
"generated": 1551926105235
]
I am not sure why Console.WriteLine(Buy.max); shows as 0 instead of 20 and Console.WriteLine(Buy.highToLow); shows as false instead of true. what am I doing wrong? I have looked for solutions to this issue for the past few hours to no avail. Any help would be greatly appreciated!
c# json parsing console-application
c# json parsing console-application
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Mar 7 at 4:50
Parker AllenParker Allen
32
32
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Parker Allen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
1
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. YourBuyandSellclasses are identical, so is theForQueryclass. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.
– Jimi
Mar 7 at 5:07
Also, you can use an attribute[JsonProperty("[OriginalPropertyName]")]if you need to change the name of a property.
– Jimi
Mar 7 at 5:13
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32
add a comment |
1
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
1
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. YourBuyandSellclasses are identical, so is theForQueryclass. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.
– Jimi
Mar 7 at 5:07
Also, you can use an attribute[JsonProperty("[OriginalPropertyName]")]if you need to change the name of a property.
– Jimi
Mar 7 at 5:13
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32
1
1
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
1
1
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. Your
Buy and Sell classes are identical, so is the ForQuery class. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.– Jimi
Mar 7 at 5:07
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. Your
Buy and Sell classes are identical, so is the ForQuery class. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.– Jimi
Mar 7 at 5:07
Also, you can use an attribute
[JsonProperty("[OriginalPropertyName]")] if you need to change the name of a property.– Jimi
Mar 7 at 5:13
Also, you can use an attribute
[JsonProperty("[OriginalPropertyName]")] if you need to change the name of a property.– Jimi
Mar 7 at 5:13
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32
add a comment |
3 Answers
3
active
oldest
votes
What they said:
- Static members are usually for helpers or factory methods, or constants
- The API is returning an array (or List)
- That string-foo replacement is just sketchy at best. Any time you are working with a standard like JSON or XML, use the libraries to convert it to an object, then manipulate
Here's a working snippet:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Buy
public ForQuery forQuery get; set;
public long volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class ForQuery2
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public int volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
var obj = JToken.Parse(sLine).ToObject<List<RootObject>>();
Console.WriteLine("Buy node:");
Console.WriteLine(" Max: " + obj[0].buy.max);
Console.WriteLine(" HighToLow: " + obj[0].buy.highToLow);
Console.WriteLine("Sell node:");
Console.WriteLine(" Max: " + obj[0].sell.max);
Console.WriteLine(" HighToLow: " + obj[0].sell.highToLow);
Console.ReadLine();
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
add a comment |
The string replace is going to remove all instances of square brackets. You'd be better off deserializing the response as a list of RootObjects.
add a comment |
class Data
public string DataPoint;
class CustomData
public Data Dp;
class Utility
public T JsonDeserialisation<T>(string jsonFile)
TextReader textReader = new StreamReader(jsonFile);
JsonTextReader jsonReader = new JsonTextReader(textReader);
return JsonSerializer.CreateDefault().Deserialize<T>(jsonReader);
Since you have all classes beforehand, you can the following code generic json deserializer. Here 'T' is CustomData class
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Parker Allen is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036305%2fjson-api-values-0-or-false%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
What they said:
- Static members are usually for helpers or factory methods, or constants
- The API is returning an array (or List)
- That string-foo replacement is just sketchy at best. Any time you are working with a standard like JSON or XML, use the libraries to convert it to an object, then manipulate
Here's a working snippet:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Buy
public ForQuery forQuery get; set;
public long volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class ForQuery2
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public int volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
var obj = JToken.Parse(sLine).ToObject<List<RootObject>>();
Console.WriteLine("Buy node:");
Console.WriteLine(" Max: " + obj[0].buy.max);
Console.WriteLine(" HighToLow: " + obj[0].buy.highToLow);
Console.WriteLine("Sell node:");
Console.WriteLine(" Max: " + obj[0].sell.max);
Console.WriteLine(" HighToLow: " + obj[0].sell.highToLow);
Console.ReadLine();
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
add a comment |
What they said:
- Static members are usually for helpers or factory methods, or constants
- The API is returning an array (or List)
- That string-foo replacement is just sketchy at best. Any time you are working with a standard like JSON or XML, use the libraries to convert it to an object, then manipulate
Here's a working snippet:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Buy
public ForQuery forQuery get; set;
public long volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class ForQuery2
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public int volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
var obj = JToken.Parse(sLine).ToObject<List<RootObject>>();
Console.WriteLine("Buy node:");
Console.WriteLine(" Max: " + obj[0].buy.max);
Console.WriteLine(" HighToLow: " + obj[0].buy.highToLow);
Console.WriteLine("Sell node:");
Console.WriteLine(" Max: " + obj[0].sell.max);
Console.WriteLine(" HighToLow: " + obj[0].sell.highToLow);
Console.ReadLine();
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
add a comment |
What they said:
- Static members are usually for helpers or factory methods, or constants
- The API is returning an array (or List)
- That string-foo replacement is just sketchy at best. Any time you are working with a standard like JSON or XML, use the libraries to convert it to an object, then manipulate
Here's a working snippet:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Buy
public ForQuery forQuery get; set;
public long volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class ForQuery2
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public int volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
var obj = JToken.Parse(sLine).ToObject<List<RootObject>>();
Console.WriteLine("Buy node:");
Console.WriteLine(" Max: " + obj[0].buy.max);
Console.WriteLine(" HighToLow: " + obj[0].buy.highToLow);
Console.WriteLine("Sell node:");
Console.WriteLine(" Max: " + obj[0].sell.max);
Console.WriteLine(" HighToLow: " + obj[0].sell.highToLow);
Console.ReadLine();
What they said:
- Static members are usually for helpers or factory methods, or constants
- The API is returning an array (or List)
- That string-foo replacement is just sketchy at best. Any time you are working with a standard like JSON or XML, use the libraries to convert it to an object, then manipulate
Here's a working snippet:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace HttpsApiTest
class Program
public class ForQuery
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Buy
public ForQuery forQuery get; set;
public long volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class ForQuery2
public bool bid get; set;
public List<int> types get; set;
public List<object> regions get; set;
public List<object> systems get; set;
public int hours get; set;
public int minq get; set;
public class Sell
public ForQuery2 forQuery get; set;
public int volume get; set;
public double wavg get; set;
public double avg get; set;
public double variance get; set;
public double stdDev get; set;
public double median get; set;
public double fivePercent get; set;
public double max get; set;
public double min get; set;
public bool highToLow get; set;
public long generated get; set;
public class RootObject
public Buy buy get; set;
public Sell sell get; set;
static void Main(string[] args)
string sURL = "https://api.evemarketer.com/ec/marketstat/json?typeid=1230®ionlimit=10000002";
StreamReader objReader = new StreamReader(WebRequest.Create(sURL).GetResponse().GetResponseStream());
string sLine = objReader.ReadLine();
var obj = JToken.Parse(sLine).ToObject<List<RootObject>>();
Console.WriteLine("Buy node:");
Console.WriteLine(" Max: " + obj[0].buy.max);
Console.WriteLine(" HighToLow: " + obj[0].buy.highToLow);
Console.WriteLine("Sell node:");
Console.WriteLine(" Max: " + obj[0].sell.max);
Console.WriteLine(" HighToLow: " + obj[0].sell.highToLow);
Console.ReadLine();
answered Mar 7 at 7:05
Sean AitkenSean Aitken
8901018
8901018
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
add a comment |
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
This worked perfectly! Thank you!
– Parker Allen
Mar 7 at 17:32
add a comment |
The string replace is going to remove all instances of square brackets. You'd be better off deserializing the response as a list of RootObjects.
add a comment |
The string replace is going to remove all instances of square brackets. You'd be better off deserializing the response as a list of RootObjects.
add a comment |
The string replace is going to remove all instances of square brackets. You'd be better off deserializing the response as a list of RootObjects.
The string replace is going to remove all instances of square brackets. You'd be better off deserializing the response as a list of RootObjects.
answered Mar 7 at 5:01
ScottyD0ntScottyD0nt
1164
1164
add a comment |
add a comment |
class Data
public string DataPoint;
class CustomData
public Data Dp;
class Utility
public T JsonDeserialisation<T>(string jsonFile)
TextReader textReader = new StreamReader(jsonFile);
JsonTextReader jsonReader = new JsonTextReader(textReader);
return JsonSerializer.CreateDefault().Deserialize<T>(jsonReader);
Since you have all classes beforehand, you can the following code generic json deserializer. Here 'T' is CustomData class
add a comment |
class Data
public string DataPoint;
class CustomData
public Data Dp;
class Utility
public T JsonDeserialisation<T>(string jsonFile)
TextReader textReader = new StreamReader(jsonFile);
JsonTextReader jsonReader = new JsonTextReader(textReader);
return JsonSerializer.CreateDefault().Deserialize<T>(jsonReader);
Since you have all classes beforehand, you can the following code generic json deserializer. Here 'T' is CustomData class
add a comment |
class Data
public string DataPoint;
class CustomData
public Data Dp;
class Utility
public T JsonDeserialisation<T>(string jsonFile)
TextReader textReader = new StreamReader(jsonFile);
JsonTextReader jsonReader = new JsonTextReader(textReader);
return JsonSerializer.CreateDefault().Deserialize<T>(jsonReader);
Since you have all classes beforehand, you can the following code generic json deserializer. Here 'T' is CustomData class
class Data
public string DataPoint;
class CustomData
public Data Dp;
class Utility
public T JsonDeserialisation<T>(string jsonFile)
TextReader textReader = new StreamReader(jsonFile);
JsonTextReader jsonReader = new JsonTextReader(textReader);
return JsonSerializer.CreateDefault().Deserialize<T>(jsonReader);
Since you have all classes beforehand, you can the following code generic json deserializer. Here 'T' is CustomData class
answered Mar 7 at 6:12
neelesh bodgalneelesh bodgal
313
313
add a comment |
add a comment |
Parker Allen is a new contributor. Be nice, and check out our Code of Conduct.
Parker Allen is a new contributor. Be nice, and check out our Code of Conduct.
Parker Allen is a new contributor. Be nice, and check out our Code of Conduct.
Parker Allen is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036305%2fjson-api-values-0-or-false%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why are all your properties static? Try removing static from properties.
– AliK
Mar 7 at 4:56
1
Why are you're trying to remove pieces of the JSON. Don't do that. It's a valid JSON. Read the stream to the end the deserialize to a simpler class structure. Your
BuyandSellclasses are identical, so is theForQueryclass. You can have just one type of each. You could just use the Properties names (Buy and Sell) to tell apart the two objects. That's all.– Jimi
Mar 7 at 5:07
Also, you can use an attribute
[JsonProperty("[OriginalPropertyName]")]if you need to change the name of a property.– Jimi
Mar 7 at 5:13
I used static because the way my code was setup, it threw an error saying it couldn't use a non-static value.
– Parker Allen
Mar 7 at 17:32