TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
VInod Mosiganti
NA
18
1.2k
JSON Response Error
May 20 2020 6:46 AM
HI Team,
I am trying to get JSON data by http url and then write Json Data console but geting bellow error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Trail05
StackTrace:
at ReadCountryData.Program.Main(String[] args) in D:\CSOM_Dev\ENRICH TRAIL\Trail05\Trail05\Program.cs:line 45
Below is the Request URL:
https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json
Code:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web;
namespace ReadCountryData
{
class Program
{
public class positionsobj
{
public positionlist positions { get; set; }
}
public class positionlist
{
public List
position { get; set; }
}
public class position
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
}
static void Main(string[] args)
{
HttpClient http = new HttpClient();
string url = "https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json";
HttpResponseMessage response = http.GetAsync(new Uri(url)).Result;
var responseBody = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(responseBody);
positionsobj position = JsonConvert.DeserializeObject
(responseBody);
foreach (position item in position.positions.position)
{
Console.WriteLine("{0}", item.CustomerID);
}
Console.ReadLine();
}
}
}
Reply
Answers (
3
)
Excel import with OpenXML
Inserting data from two forms into sql table