Deserialize JSON string into a list for dropdownlist in C# -
i have windows form application , deserialize json string i'm getting web address can 2 values it, how go doing this?
below code have json string, , if go url it's getting, can see json string. want item name, , current cost of it. can see cost under current key.
private void grabprices() { using (webclient webclient = new system.net.webclient()) { webclient n = new webclient(); var json = n.downloadstring("http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=1513"); string valueoriginal = convert.tostring(json); console.writeline(json); } }
it's going iterating through sqlite database , getting same info multiple items based on item id, i'll able myself.
edit i'd utilize json.net if possible, i've been trying utilize , seems easy enough, i'm still having trouble.
okay first of need know json structure, sample:
[{ name: "micheal", age: 20 }, { name: "bob", age: 24 }]
with info can derive c# object
public class person { public string name {get;set;} public int age {get;set;} }
now can utilize json.net deserialize json c#:
var people = jsonconvert.deserializeobject<list<person>>(jsonstring);
if @ original json array of objects, deal have used list<t>
.
key things remember, need have c# object mirror in properties of json object. if don't have list, don't need list<t>
.
if json objects have camel casing, , want converted c# conventions, utilize this:
var people = jsonconvert.deserializeobject<list<person>>( jsonstring, new jsonserializersettings { contractresolver = new camelcasepropertynamescontractresolver() });
c# json
No comments:
Post a Comment