Good afternoon, I decided to ask because I have been caught in this for 3 days and no matter how much I have searched, I have not found a solution to my problem. Access a Web Service via C #, HttpClient, and get a Json in the following format:
{
"games": [
{
"IdJogo": "1",
"Titulo": "No Man's Sky",
"DtaLancamento": "Junho 2016",
"ResumoBR": "Em No Man's Sky você assume o papel de um explorador planetário com uma nave espacial, permitindo-lhes explorar a superfície de vários planetas e interagir com a flora e fauna, e viajar pelo espaço, entrar em combate com forças inimigas e viajar a outros planetas.",
"NomeImg": "NoManSky.jpg"
},
{
"IdJogo": "2",
"Titulo": "Starbound",
"DtaLancamento": "Dezembro 2013",
"ResumoBR": "Starbound é um sandbox/open world, nele você vive em uma espaçonave e pode explorar diferentes mundos, sistemas solares, galáxias, etc. As possibilidades são praticamente infinitas!",
"NomeImg": "Starbound.jpg"
}
I'm using Json.net (newtonsoftjson) to convert each "Game" contained in Json to an object with the same attributes as in Json, but I get a lot of errors. I'm currently converting this way:
string jsonR = resposta.Content.ReadAsStringAsync().Result;
foreach (JObject elemento in jsonR)
{
Game game = JsonConvert.DeserializeObject<Game>(elemento.ToString());
}
However, I get the following error:
It is not possible to convert an object of type Newtonsoft.Json.Linq.JValue in type Newtonsoft.Json.Linq.JObject
and when I try to put the JValue type inside the foreach, I get the error:
Error converting value 123 to type 'WpfApplication1.Game'.Path', line1 position 3.
Sorry for any error while posting this way, but I've already reviewed the Newtonsoft documentation, I've reviewed google and nothing helped.