c# - How do I deserialise this JSON? -


i haven't done json before... missing step.

here example of json want deserialise:

{"item":{"icon":"http://services.runescape.com/m=itemdb_rs/4765_obj_sprite.gif?id=4798","icon_large":"http://services.runescape.com/m=itemdb_rs/4765_obj_big.gif?id=4798","id":4798,"type":"ammo","typeicon":"http://www.runescape.com/img/categories/ammo","name":"adamant brutal","description":"blunt adamantite arrow...ouch","current":{"trend":"neutral","price":237},"today":{"trend":"neutral","price":0},"members":"true","day30":{"trend":"positive","change":"+1.0%"},"day90":{"trend":"negative","change":"-0.0%"},"day180":{"trend":"positive","change":"+0.0%"}}} 

i put "json 2 c#" , ended creating new .cs file:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace rstool.models {      public class current     {         public string trend { get; set; }         public int price { get; set; }     }      public class today     {         public string trend { get; set; }         public int price { get; set; }     }      public class day30     {         public string trend { get; set; }         public string change { get; set; }     }      public class day90     {         public string trend { get; set; }         public string change { get; set; }     }      public class day180     {         public string trend { get; set; }         public string change { get; set; }     }      public class item     {         public string icon { get; set; }         public string icon_large { get; set; }         public int id { get; set; }         public string type { get; set; }         public string typeicon { get; set; }         public string name { get; set; }         public string description { get; set; }         public current current { get; set; }         public today today { get; set; }         public string members { get; set; }         public day30 day30 { get; set; }         public day90 day90 { get; set; }         public day180 day180 { get; set; }     }      public class rootobject     {         public item item { get; set; }     } } 

so, have class. can retrieve json location string, have no idea how deserialise it... have installed newtonsoft.json , have tried using populateobject , deserializer not luck...

assuming json stored string called "json", how go storing query , retrieving item name, example?

use:

var deserialized = jsonconvert.deserializeobject<rootobject>(json); 

i tested given code supplied.

you can access properties of object normal:

messagebox.show(deserialized.item.name); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -