Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing Json in C# with JSON.NET
    text
    copied!<p>I am developing an application in c# that gets the players backpack value on a game called TF2 using Backpack.tf's api.</p> <p>At the moment the code is:</p> <pre><code> (MAIN CLASS) JsonConvert.DeserializeObject&lt;Json1&gt;(json); (END OF MAIN CLASS) public class Json1 { public static List&lt;Json2&gt; response { get; set; } } public class Json2 { public static int success { get; set; } public static int current_time { get; set; } public static IEnumerable&lt;Json4&gt; players { get; set; } } public class Json4 { public static int steamid { get; set; } public static int success { get; set; } public static double backpack_value { get; set; } public static string name { get; set; } } </code></pre> <p>I've cut out all the other crap out of the main class etc but suffice it to say that yes i've got the json code into the json string ready for deserializing (Tested it with Console.Writeline) </p> <p>The problem is. Whenever I use things like Json4.name (when writing to console) it always returns 0. </p> <p>Sorry if I've made a stupid mistake but I think I've tried things like removing static, changing variable types etc but I still can't get it to work. Please note this is my first attemopt at deserializing Json code and I wrote the classes at bottom myself because some reason <a href="http://json2csharp.com/" rel="nofollow">http://json2csharp.com/</a> didn't work. Heres the Json I am trying to deserialize: </p> <pre><code>{ "response":{ "success":1, "current_time":1365261392, "players":{ "0":{ "steamid":"76561198045802942", "success":1, "backpack_value":12893.93, "backpack_update":1365261284, "name":"Brad Pitt", "stats_tf_reputation":2257, "stats_tf_supporter":1, "notifications":0 }, "1":{ "steamid":"76561197960435530", "success":1, "backpack_value":4544.56, "backpack_update":1365254794, "name":"Robin", "notifications":0 } } } } </code></pre> <p>(formatting messed up a bit. Also please excuse some spelling mistakes :) )</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload