- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Deserializing JSON to .NET object using Newtonsoft json in C# and pick only one value from the array?
The WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI.
The WebClient class uses the WebRequest class to provide access to resources. WebClient instances can access data with any WebRequest descendant registered with the WebRequest.RegisterPrefix method.
DownloadString Downloads a String from a resource and returns a String.
If your request requires an optional header, you must add the header to the Headers collection
Example
In the below example we are calling the url "https://jsonplaceholder.typicode.com/posts"
The example is then deserialized to User array
From the user array we are printing the first array value
Example
class Program{ static void Main(string[] args){ var client = new WebClient(); var json = client.DownloadString("https://jsonplaceholder.typicode.com/posts"); var userPosts = JsonConvert.DeserializeObject<User[]>(json); System.Console.WriteLine(userPosts[0].title); Console.ReadLine(); } } public class User{ public string userId { get; set; } public string id { get; set; } public string title { get; set; } public string body { get; set; } }
Output
sunt aut facere repellat provident occaecati excepturi optio reprehenderit
- Related Articles
- How to get formatted JSON in .NET using C#?
- From JSON object to an array in JavaScript
- How to handle the errors generated while deserializing a JSON in Java?
- How to work with XML and JSON in .NET?
- How to add elements to JSON Object using JSON-lib API in Java?
- How to create a JSON Array using Object Model in Java?
- Create array from JSON object JavaScript
- How to modify an array value of a JSON object in JavaScript?
- How to convert the JSON object to a bean using JSON-lib API in Java?
- How to read data from JSON array using JavaScript?
- How to construct a JSON object from a subset of another JSON object in Java?
- How to convert a Map to JSON object using JSON-lib API in Java?
- How to convert JSON text to JavaScript JSON object?
- How to convert an array to JSON Array using JSON-lib API in Java?\n
- How to convert a JSON array to array using JSON-lib API in Java?\n

Advertisements