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
Salman Mushtaq
NA
284
221.5k
Populate ComboBox from JSON Object
Dec 7 2017 3:28 AM
Hello, I have below Json
[
{
"customerid": 1,
"name": "ABS",
"email": "true",
"reference": "2016-03-21T10:44:32+03:00",
"status": 0,
"dateupdated": "2017-12-07T04:56:05.583"
},
{
"customerid": 2,
"name": "BMS",
"email": "true",
"reference": "2016-03-13T19:17:54+03:00",
"status": 0,
"dateupdated": "2017-12-07T04:56:05.757"
},
{
"customerid": 3,
"name": "XYA",
"email": "true",
"reference": "2016-03-13T19:17:54+03:00",
"status": 0,
"dateupdated": "2017-12-07T04:56:05.757"
}
]
In my windows form I create class API.cs
class
API
{
}
public
class
RootObject
{
public
int
customerid {
get
;
set
; }
public
string
name {
get
;
set
; }
public
string
email {
get
;
set
; }
public
DateTime reference {
get
;
set
; }
public
int
status {
get
;
set
; }
public
DateTime dateupdated {
get
;
set
; }
}
I need to populate combo box customer_cb with "name". I use DataContractJsonSerializer
WebClient client =
new
WebClient();
string
json = client.DownloadString(url);
using
(var ms =
new
MemoryStream(Encoding.Unicode.GetBytes(json)))
{
DataContractJsonSerializer deserializer =
new
DataContractJsonSerializer(
typeof
(RootObject));
RootObject obj = (RootObject)deserializer.ReadObject(ms);
// Assign data to combo box
foreach
(var name
in
obj.name)
{
ComboboxItem item =
new
ComboboxItem();
item.Text = name.ToString();
customer_cb.Items.Add(item);
}
}
When I run the application I get error
Object Reference not
set
to an instance of an
object
Please help.
Reply
Answers (
2
)
how to show location in google map dynamic mvc
textarea content should affect the database