0

I want to read the jsons nested array from a HTTP Response using VB.Net or C#.

For Example I want to get the Name:

{
"Name": "Brian",
"address": {
   "street": "8nd Roadstreet"
 }
}

I've been using VB.Net so far, and it works using the following Code:

Using streamReader = New StreamReader(httpResponse.GetResponseStream())
    Json1 = JObject.Parse(streamReader.ReadToEnd())("Name")
    MessageBox.Show("Json Text:" & Json1.ToString)
End Using

Output is: Brian

But I don't know how to get the Street. Using the same Code above doesn't work as the Street is in the Address.

Would be great if someone could help me out here.

1 Answers1

0

Create a class for the Http Response like below .

  public class Address    {
        public string street { get; set; } 
    }

    public class Root    {
        public string Name { get; set; } 
        public Address address { get; set; } 
    }

And You can use Newtonsoft to deserialize the Json .

Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
Test12345
  • 1,625
  • 1
  • 12
  • 21