Click here to Skip to main content
15,439,290 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have the following code to connect to a Json on a server.
I can connected and read the file succesfully.
But i just want now to extract some fields, really i am stocked: I don't know
even i have seen at lot examples (Including one in this forum)

public List<Paquete> GetPaquete()
 {

          url = url + codigo + clave + keyAPI + keyPaso;
          RestClient client = new RestClient(url);

          RestRequest request = new RestRequest(url, Method.Get);
          request.RequestFormat = DataFormat.Json;
          request.AddHeader("Context-Type", "application/json");
          var response = client.Execute(request);


          if (response.IsSuccessful)
          {
              var listadof = JsonConvert.DeserializeObject<List<Paquete>>(url);
              var peso = listadof[0];

              return listadof;
          }
          else
          {
              var error = response.ErrorMessage;

          }
          return null;
      }


Also i have this class
[Serializable]
public class Paquete
{
    [JsonProperty("peso")]
    public string peso { get; set; }

    [JsonProperty("trackingnumber")]
    public string trackingNumber { get; set; }
}


What I have tried:

Trying to deserialized a json from a server
Posted
Updated 21-Jul-22 3:39am

1 solution

I have written an article that will answer this question and more: Working with JSON in C# & VB[^]
 
Share this answer
 
Comments
Luis M. Rojas 21-Jul-22 10:20am    
Excellent, that is it. Great. Thanks at lot. it is works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900