Deserialize JSON C# Json.net -



Deserialize JSON C# Json.net -

this question has reply here:

how can parse json string cause illegal c# identifiers? 2 answers

i trying deserialize json response api.

the info looks this

{ "response": { "6112": { "id": 6112, "title": "additionalphotos" }, "5982": { "id": 5982, "title": "bikeride" }, "total_records": "20", "returned_count": 10, "returned_records": "1-10" } }

c# class:

public class products { public class product { public string id { get; set; } public string title { get; set; } } public product product { get; set; } } public class ss { public dictionary<string, products.product> response { get; set; } public string total_records { get; set; } }

serialization code

ss res = newtonsoft.json.jsonconvert.deserializeobject<ss>(jsondata());

i can work without total_records entry , below deserializng dictionary <string , product>. cannot figure out how work. error

error converting value "20" type 'products+product'. path 'response.total_records'

i know why error, i'm unsure how can proceed without going in , substringing total_records down. have no command on api data.

edit: guys fast, still getting putting classes up

first json not valid one, should

{ "response":{ "6112":{ "id":"6112", "title":"additional photos", }, "5982":{ "id":"5982", "title":"bike ride", }, "total_records": "20", "returned_count": "10", "returned_records": "1-10", } }

if mean response contain list should

{ "response":{ "myarray": [ { "id":"6112", "title":"additional photos", }, { "id":"5982", "title":"bike ride", } ], "total_records": "20", "returned_count": "10", "returned_records": "1-10", } }

so code this

public class myarray { public string id { get; set; } public string title { get; set; } } public class response { public list<myarray> myarray { get; set; } public string total_records { get; set; } public string returned_count { get; set; } public string returned_records { get; set; } } public class rootobject { public response response { get; set; } }

c# json json.net deserialization

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -