How to get a JSON response as an array of objects in asp.net? [duplicate]
This question already has an answer here:
Convert json to a C# array?
3 answers
Parse JSON in C#
7 answers
Web API method return JSON data
1 answer
WebAPI Return JSON array without root node
2 answers
I am making a Report Card System and I would like to know how get a JSON response that consists of seeded data as an array of objects instead of a singular object. So far I used a IDictionary method but it is only giving me one object eg.SubjectMark = { Math:76 }
, How do I get all my seeded data instead of one instance , for example:
Report = [{
Subject:Maths
Mark: 76
},
{
Subject:IT
Mark: 90
},]
or at least
SubjectMark = [{ Math:76 },{ IT:90 }]
I am a beginner please let me know if i should add more context, Thank you.
c# asp.net asp.net-web-api
marked as duplicate by Panagiotis Kanavos, ewolden, Alexei Levenkov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 6:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 2 more comments
This question already has an answer here:
Convert json to a C# array?
3 answers
Parse JSON in C#
7 answers
Web API method return JSON data
1 answer
WebAPI Return JSON array without root node
2 answers
I am making a Report Card System and I would like to know how get a JSON response that consists of seeded data as an array of objects instead of a singular object. So far I used a IDictionary method but it is only giving me one object eg.SubjectMark = { Math:76 }
, How do I get all my seeded data instead of one instance , for example:
Report = [{
Subject:Maths
Mark: 76
},
{
Subject:IT
Mark: 90
},]
or at least
SubjectMark = [{ Math:76 },{ IT:90 }]
I am a beginner please let me know if i should add more context, Thank you.
c# asp.net asp.net-web-api
marked as duplicate by Panagiotis Kanavos, ewolden, Alexei Levenkov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 6:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@AlexeiLevenkov why? I didn't sayJson.Net is what you need
. I saidJavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required
– Panagiotis Kanavos
Nov 22 '18 at 7:44
|
show 2 more comments
This question already has an answer here:
Convert json to a C# array?
3 answers
Parse JSON in C#
7 answers
Web API method return JSON data
1 answer
WebAPI Return JSON array without root node
2 answers
I am making a Report Card System and I would like to know how get a JSON response that consists of seeded data as an array of objects instead of a singular object. So far I used a IDictionary method but it is only giving me one object eg.SubjectMark = { Math:76 }
, How do I get all my seeded data instead of one instance , for example:
Report = [{
Subject:Maths
Mark: 76
},
{
Subject:IT
Mark: 90
},]
or at least
SubjectMark = [{ Math:76 },{ IT:90 }]
I am a beginner please let me know if i should add more context, Thank you.
c# asp.net asp.net-web-api
This question already has an answer here:
Convert json to a C# array?
3 answers
Parse JSON in C#
7 answers
Web API method return JSON data
1 answer
WebAPI Return JSON array without root node
2 answers
I am making a Report Card System and I would like to know how get a JSON response that consists of seeded data as an array of objects instead of a singular object. So far I used a IDictionary method but it is only giving me one object eg.SubjectMark = { Math:76 }
, How do I get all my seeded data instead of one instance , for example:
Report = [{
Subject:Maths
Mark: 76
},
{
Subject:IT
Mark: 90
},]
or at least
SubjectMark = [{ Math:76 },{ IT:90 }]
I am a beginner please let me know if i should add more context, Thank you.
This question already has an answer here:
Convert json to a C# array?
3 answers
Parse JSON in C#
7 answers
Web API method return JSON data
1 answer
WebAPI Return JSON array without root node
2 answers
c# asp.net asp.net-web-api
c# asp.net asp.net-web-api
asked Nov 21 '18 at 8:51
user10174623
marked as duplicate by Panagiotis Kanavos, ewolden, Alexei Levenkov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 6:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Panagiotis Kanavos, ewolden, Alexei Levenkov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 6:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@AlexeiLevenkov why? I didn't sayJson.Net is what you need
. I saidJavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required
– Panagiotis Kanavos
Nov 22 '18 at 7:44
|
show 2 more comments
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@AlexeiLevenkov why? I didn't sayJson.Net is what you need
. I saidJavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required
– Panagiotis Kanavos
Nov 22 '18 at 7:44
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@AlexeiLevenkov why? I didn't say
Json.Net is what you need
. I said JavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required– Panagiotis Kanavos
Nov 22 '18 at 7:44
@AlexeiLevenkov why? I didn't say
Json.Net is what you need
. I said JavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required– Panagiotis Kanavos
Nov 22 '18 at 7:44
|
show 2 more comments
2 Answers
2
active
oldest
votes
You need to desearilize Json Object as collection.
public class ReportCard
{
public string Subject
{
get;
set;
}
public int Mark
{
get;
set;
}
}
List<ReportCard> ReportCard = JsonConvert.DeserializeObject<List<ReportCard>>
(json);
add a comment |
Use this
var response = await client.PostAsync(**your_api_url**, formContent);
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<**your_object_class**>(json);
YOUR_OBJECT_CLASS: use this http://json2csharp.com/
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to desearilize Json Object as collection.
public class ReportCard
{
public string Subject
{
get;
set;
}
public int Mark
{
get;
set;
}
}
List<ReportCard> ReportCard = JsonConvert.DeserializeObject<List<ReportCard>>
(json);
add a comment |
You need to desearilize Json Object as collection.
public class ReportCard
{
public string Subject
{
get;
set;
}
public int Mark
{
get;
set;
}
}
List<ReportCard> ReportCard = JsonConvert.DeserializeObject<List<ReportCard>>
(json);
add a comment |
You need to desearilize Json Object as collection.
public class ReportCard
{
public string Subject
{
get;
set;
}
public int Mark
{
get;
set;
}
}
List<ReportCard> ReportCard = JsonConvert.DeserializeObject<List<ReportCard>>
(json);
You need to desearilize Json Object as collection.
public class ReportCard
{
public string Subject
{
get;
set;
}
public int Mark
{
get;
set;
}
}
List<ReportCard> ReportCard = JsonConvert.DeserializeObject<List<ReportCard>>
(json);
answered Nov 21 '18 at 9:02
Hamza HaiderHamza Haider
666315
666315
add a comment |
add a comment |
Use this
var response = await client.PostAsync(**your_api_url**, formContent);
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<**your_object_class**>(json);
YOUR_OBJECT_CLASS: use this http://json2csharp.com/
add a comment |
Use this
var response = await client.PostAsync(**your_api_url**, formContent);
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<**your_object_class**>(json);
YOUR_OBJECT_CLASS: use this http://json2csharp.com/
add a comment |
Use this
var response = await client.PostAsync(**your_api_url**, formContent);
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<**your_object_class**>(json);
YOUR_OBJECT_CLASS: use this http://json2csharp.com/
Use this
var response = await client.PostAsync(**your_api_url**, formContent);
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<**your_object_class**>(json);
YOUR_OBJECT_CLASS: use this http://json2csharp.com/
answered Nov 21 '18 at 9:07
begovskybegovsky
11
11
add a comment |
add a comment |
You can get solution convert json to array
– Darji Sonali
Nov 21 '18 at 8:57
@DarjiSonali that's not a good link. JavaScriptSerializer is obsolete. Web API uses Json.NET already
– Panagiotis Kanavos
Nov 21 '18 at 9:06
Why the question? JSON is Web API's default serialization format. If you return an array of objects, it will be serialized into a JSON array. If your action accepts an array of objects as a parameter, the corresponding element from the payload will be deserialized automatically. What does your code look like and why use a dictionary in the first place?
– Panagiotis Kanavos
Nov 21 '18 at 9:08
@PanagiotisKanavos It is somewhat confusing that you've said that suggested answers are wrong like "Yes, Json.Net is what you need" and yet you recommend to use JSON.Net... (Likely OP actually don't need any manual serialization at all but it is not what they are asking).
– Alexei Levenkov
Nov 22 '18 at 6:36
@AlexeiLevenkov why? I didn't say
Json.Net is what you need
. I saidJavaScriptSerializer is obsolete
and that Web API already uses JSON.NET. Which makes this question unclear - all the OP has to do is return the desired object, no extra serialization is required– Panagiotis Kanavos
Nov 22 '18 at 7:44