0

How i can Fetch data from an Json Api like that:

https://jsonplaceholder.typicode.com/todos/1

responseBody.title

i Already have this:

HttpResponseMessage response = await 
client.GetAsync("https://jsonplaceholder.typicode.com/todos/1");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
1
  • Your life will get massively easier if you spend 15 minutes looking into QuickType.io Commented Aug 18, 2019 at 23:57

1 Answer 1

1

You can use Newtonsoft.Json library for working with JSON data. You can use serialization/deserialization or LINQ to JSON methods

For example based on your code:

HttpResponseMessage response = await client.GetAsync("https://jsonplaceholder.typicode.com/todos/1");
string responseBody = await response.Content.ReadAsStringAsync();

// LINQ to JSON method
JObject jsonObject = JObject.Parse(responseBody);
int userId = int.Parse(jsonObject["userId"].ToString());
int id = int.Parse(jsonObject["id"].ToString());
string title = jsonObject["title"].ToString();
bool completed = bool.Parse(jsonObject["completed"].ToString());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.