Parsing in C# using JSON.Net (very confusing!) -


i want parse following json:

{"0":{"igloo_id":"0","name":"igloo removal","cost":"0"},"1":{"igloo_id":"1","name":"basic igloo","cost":"1500"},"2":{"igloo_id":"2","name":"candy igloo","cost":"1500"},"3":{"igloo_id":"3","name":"deluxe blue igloo","cost":"4000"},"4":{"igloo_id":"4","name":"big candy igloo","cost":"4000"},"5":{"igloo_id":"5","name":"secret stone igloo","cost":"2000"},"6":{"igloo_id":"6","name":"snow igloo","cost":"1000"},"8":{"igloo_id":"8","name":"secret deluxe stone igloo","cost":"5000"},"9":{"igloo_id":"9","name":"deluxe snow igloo","cost":"3000"},"10":{"igloo_id":"10","name":"bamboo hut","cost":"3200"},"11":{"igloo_id":"11","name":"log cabin","cost":"4100"},"12":{"igloo_id":"12","name":"gym","cost":"4800"},"13":{"igloo_id":"13","name":"split level igloo","cost":"4600"},"14":{"igloo_id":"14","name":"candy split level igloo","cost":"4600"},"15":{"igloo_id":"15","name":"snowglobe","cost":"3700"},"16":{"igloo_id":"16","name":"ice castle","cost":"2400"},"17":{"igloo_id":"17","name":"split level snow igl","cost":"4600"},"18":{"igloo_id":"18","name":"fish bowl","cost":"2400"},"19":{"igloo_id":"19","name":"tent","cost":"2700"},"20":{"igloo_id":"20","name":"jack o' lantern","cost":"2700"},"21":{"igloo_id":"21","name":"backyard igloo","cost":"4200"},"22":{"igloo_id":"22","name":"pink ice palace","cost":"2400"},"23":{"igloo_id":"23","name":"ship igloo","cost":"4300"},"24":{"igloo_id":"24","name":"dojo igloo","cost":"1300"},"25":{"igloo_id":"25","name":"gingerbread house","cost":"2100"},"26":{"igloo_id":"26","name":"restaurant igloo","cost":"4800"},"27":{"igloo_id":"27","name":"tree house igloo","cost":"4500"},"28":{"igloo_id":"28","name":"theatre igloo","cost":"4600"},"29":{"igloo_id":"29","name":"circus tent","cost":"0"},"30":{"igloo_id":"30","name":"snowy backyard igloo","cost":"3000"},"31":{"igloo_id":"31","name":"cave igloo","cost":"1500"},"32":{"igloo_id":"32","name":"green clover igloo","cost":"2050"},"33":{"igloo_id":"33","name":"grey ice castle","cost":"2400"},"35":{"igloo_id":"35","name":"cozy cottage igloo","cost":"2500"},"36":{"igloo_id":"36","name":"estate igloo","cost":"2500"},"37":{"igloo_id":"37","name":"in half igloo","cost":"2300"},"38":{"igloo_id":"38","name":"shadowy keep","cost":"2400"},"39":{"igloo_id":"39","name":"dragon's lair","cost":"3000"},"40":{"igloo_id":"40","name":"mermaid cove","cost":"3030"},"41":{"igloo_id":"41","name":"whale's mouth","cost":"2700"},"42":{"igloo_id":"42","name":"trick-or-treat igloo","cost":"2000"},"43":{"igloo_id":"43","name":"deluxe gingerbread house","cost":"0"},"45":{"igloo_id":"45","name":"invisible snowy","cost":"0"},"46":{"igloo_id":"46","name":"invisible beach","cost":"0"},"47":{"igloo_id":"47","name":"invisible forest","cost":"0"},"48":{"igloo_id":"48","name":"invisible mountain","cost":"0"},"49":{"igloo_id":"49","name":"shipwreck igloo","cost":"900"},"50":{"igloo_id":"50","name":"wildlife den","cost":"900"},"51":{"igloo_id":"51","name":"medieval manor","cost":"1200"},"52":{"igloo_id":"52","name":"warehouse","cost":"950"},"53":{"igloo_id":"53","name":"pineapple igloo","cost":"0"},"54":{"igloo_id":"54","name":"creepy cavern","cost":"1500"},"55":{"igloo_id":"55","name":"frost bite palace","cost":"0"},"56":{"igloo_id":"56","name":"fresh baked gingerbread house","cost":"2500"},"57":{"igloo_id":"57","name":"penthouse","cost":"4000"},"58":{"igloo_id":"58","name":"vip penthouse","cost":"0"},"59":{"igloo_id":"59","name":"invisible age of dinosaurs","cost":"0"},"60":{"igloo_id":"60","name":"puffle tree fort","cost":"0"},"61":{"igloo_id":"61","name":"secret base","cost":"1600"},"62":{"igloo_id":"62","name":"death star igloo","cost":"1000"},"63":{"igloo_id":"63","name":"beach party igloo","cost":"1500"},"64":{"igloo_id":"64","name":"gymnasium igloo","cost":"0"},"65":{"igloo_id":"65","name":"magical hideout","cost":"1500"},"66":{"igloo_id":"66","name":"eerie castle","cost":"2000"},"67":{"igloo_id":"67","name":"sweet swirl igloo","cost":"0"},"68":{"igloo_id":"68","name":"train station igloo","cost":"1100"},"69":{"igloo_id":"69","name":"main event igloo","cost":"1000"},"70":{"igloo_id":"70","name":"cp airliner","cost":"1200"}} 

i need way retrieve igloo_id, name , cost.

i've tried following, it's not want

list<igloo> iglooslist = jsonconvert.deserializeobject<list<igloo>>(itemjson); 

this structure of class

namespace canvas {     public class igloo     {         public int cost;         public int igloo_id;         public string name;          public int cost         {                         {                 return cost;             }         }          public int id         {                         {                 return igloo_id;             }         }          public string name         {                         {                 return name;             }         }     } } 

i'm not entirely sure understand want. code posted generated exception when tried running it,

additional information: cannot deserialize current json object (e.g. {"name":"value"}) type 'system.collections.generic.list1[consoleapplication2.program+igloo]' because type requires json array (e.g. [1,2,3]) deserialize correctly.

it did deserialize correctly if used:

var iglooslist = jsonconvert.deserializeobject<dictionary<string, igloo>>( json ); 

if want loop through use:

foreach( var igloo in iglooslist.values ) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -