I'm trying to consume a JSON, but in the structure I've developed the code does not return me data. Could you please help me and explain the concept of consumption and how does the JSON framework work?
Code that I developed, does not return LomadeeLink data.
var json = new System.Net.WebClient().DownloadString("http://bws.buscape.com.br/service/createLinks/lomadee/7569446956636c7142716f3d/BR/?sourceId=28777832&format=json&link1=http://www.walmart.com.br/produto/Telefonia/Smartphones/Motorola/471928-motorola-moto-g-2-geracao-dtv-colors-preto-tv-digital-dual-chip-quad-core-16gb-2-capas-colori&link2=http://www.walmart.com.br/produto/Telefonia/Smartphones/Motorola/471928-motorola-moto-g-2-geracao-dtv-colors-preto-tv-digital-dual-chip-quad-core-16gb-2-capas-colori");
LomadeeLinks produtos = Newtonsoft.Json.JsonConvert.DeserializeObject<LomadeeLinks>(json.ToString());
I created the classes this way because JSON returns irrelevant data, I just select the relevant data that is included in the class.
public class LomadeeLinks {
public List<LomadeeLink> lomadeelinks { get; set; }
}
public class LomadeeLink {
public int id { get; set; }
public int code { get; set; }
public string originallink { get; set; }
public string redirectlink { get; set; }
}
JSON
{
"totallooseoffers": 0,
"details": {
"date": {
"valid": true,
"eonandyear": {
"lowestsetbit": 0
},
"hour": 10,
"month": 8,
"year": 2015,
"timezone": -180,
"millisecond": 360,
"xmlschematype": {
"prefix": "",
"localpart": "dateTime",
"namespaceuri": "http://www.w3.org/2001/XMLSchema"
},
"day": 25,
"minute": 37,
"second": 14
},
"code": 0,
"elapsedtime": 1,
"applicationid": "7569446956636c7142716f3d",
"message": "success",
"status": "success"
},
"lomadeelinks": [
{
"lomadeelink": {
"originallink": "http://www.walmart.com.br/produto/Telefonia/Smartphones/Motorola/471928-motorola-moto-g-2-geracao-dtv-colors-preto-tv-digital-dual-chip-quad-core-16gb-2-capas-colori",
"code": 0,
"id": 1,
"redirectlink": "http://links.lomadee.com/ls/OUlzRDtMeThBa2FJaTsyODc3NzgzMjswOzY1ODM7MDs1NTc2O0JSOzM7aHR0cCUzQSUyRiUyRnd3dy53YWxtYXJ0LmNvbS5iciUyRnByb2R1dG8lMkZUZWxlZm9uaWElMkZTbWFydHBob25lcyUyRk1vdG9yb2xhJTJGNDcxOTI4LW1vdG9yb2xhLW1vdG8tZy0yLWdlcmFjYW8tZHR2LWNvbG9ycy1wcmV0by10di1kaWdpdGFsLWR1YWwtY2hpcC1xdWFkLWNvcmUtMTZnYi0yLWNhcGFzLWNvbG9yaTswOzA-.html"
}
},
{
"lomadeelink": {
"originallink": "http://www.walmart.com.br/produto/Telefonia/Smartphones/Motorola/471928-motorola-moto-g-2-geracao-dtv-colors-preto-tv-digital-dual-chip-quad-core-16gb-2-capas-colori",
"code": 0,
"id": 2,
"redirectlink": "http://links.lomadee.com/ls/aH5haTtDU0VPc2U2ZTsyODc3NzgzMjswOzY1ODM7MDs1NTc2O0JSOzM7aHR0cCUzQSUyRiUyRnd3dy53YWxtYXJ0LmNvbS5iciUyRnByb2R1dG8lMkZUZWxlZm9uaWElMkZTbWFydHBob25lcyUyRk1vdG9yb2xhJTJGNDcxOTI4LW1vdG9yb2xhLW1vdG8tZy0yLWdlcmFjYW8tZHR2LWNvbG9ycy1wcmV0by10di1kaWdpdGFsLWR1YWwtY2hpcC1xdWFkLWNvcmUtMTZnYi0yLWNhcGFzLWNvbG9yaTswOzA-.html"
}
}
],
"totalpages": 1,
"page": 1,
"totalresultsavailable": 2,
"totalresultsreturned": 2
}