Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
I have a class like this;
public class MyStok
{
public int STId { get; set; }
public int SM { get; set; }
public string CA { get; set; }
public string Br { get; set; }
public string BNo { get; set; }
public decimal Vat { get; set; }
public decimal Price { get; set; }
}
I deserilaze like this;
string sc= e.ExtraParams["sc"].ToString();
MyStok myobj = JSON.Deserialize<MyStok>(sc);
my output seems to like this ( string sc) on fiddler
[
{
"STId": 2,
"CA": "hbh",
"Br": "jhnj",
"SM": 20,
"Vat": 10,
"Price": 566,
"BNo": "1545545"
}
]
but I get the error Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
whats wrong in those codes.
thank you .
c# asp.net json
add a comment |
I have a class like this;
public class MyStok
{
public int STId { get; set; }
public int SM { get; set; }
public string CA { get; set; }
public string Br { get; set; }
public string BNo { get; set; }
public decimal Vat { get; set; }
public decimal Price { get; set; }
}
I deserilaze like this;
string sc= e.ExtraParams["sc"].ToString();
MyStok myobj = JSON.Deserialize<MyStok>(sc);
my output seems to like this ( string sc) on fiddler
[
{
"STId": 2,
"CA": "hbh",
"Br": "jhnj",
"SM": 20,
"Vat": 10,
"Price": 566,
"BNo": "1545545"
}
]
but I get the error Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
whats wrong in those codes.
thank you .
c# asp.net json
add a comment |
I have a class like this;
public class MyStok
{
public int STId { get; set; }
public int SM { get; set; }
public string CA { get; set; }
public string Br { get; set; }
public string BNo { get; set; }
public decimal Vat { get; set; }
public decimal Price { get; set; }
}
I deserilaze like this;
string sc= e.ExtraParams["sc"].ToString();
MyStok myobj = JSON.Deserialize<MyStok>(sc);
my output seems to like this ( string sc) on fiddler
[
{
"STId": 2,
"CA": "hbh",
"Br": "jhnj",
"SM": 20,
"Vat": 10,
"Price": 566,
"BNo": "1545545"
}
]
but I get the error Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
whats wrong in those codes.
thank you .
c# asp.net json
I have a class like this;
public class MyStok
{
public int STId { get; set; }
public int SM { get; set; }
public string CA { get; set; }
public string Br { get; set; }
public string BNo { get; set; }
public decimal Vat { get; set; }
public decimal Price { get; set; }
}
I deserilaze like this;
string sc= e.ExtraParams["sc"].ToString();
MyStok myobj = JSON.Deserialize<MyStok>(sc);
my output seems to like this ( string sc) on fiddler
[
{
"STId": 2,
"CA": "hbh",
"Br": "jhnj",
"SM": 20,
"Vat": 10,
"Price": 566,
"BNo": "1545545"
}
]
but I get the error Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
whats wrong in those codes.
thank you .
c# asp.net json
c# asp.net json
edited Mar 3 '16 at 22:37
Danny Fardy Jhonston Bermúdez
4,83651833
4,83651833
asked Jul 20 '13 at 11:58
sakir
2,08062349
2,08062349
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
It looks like the string contains an array with a single MyStok
object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:
MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
You could also deserialize the array into a list of MyStok
objects, and take the object at index zero.
var myobjList = JSON.Deserialize<List<MyStok>>(sc);
var myObj = myobjList[0];
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
add a comment |
For array type Please try this one.
List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
Please See here for details to deserialise Json
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
add a comment |
HttpClient webClient = new HttpClient();
Uri uri = new Uri("your url");
HttpResponseMessage response = await webClient.GetAsync(uri)
var jsonString = await response.Content.ReadAsStringAsync();
var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17762032%2fcannot-deserialize-the-current-json-array-e-g-1-2-3-into-type%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks like the string contains an array with a single MyStok
object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:
MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
You could also deserialize the array into a list of MyStok
objects, and take the object at index zero.
var myobjList = JSON.Deserialize<List<MyStok>>(sc);
var myObj = myobjList[0];
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
add a comment |
It looks like the string contains an array with a single MyStok
object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:
MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
You could also deserialize the array into a list of MyStok
objects, and take the object at index zero.
var myobjList = JSON.Deserialize<List<MyStok>>(sc);
var myObj = myobjList[0];
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
add a comment |
It looks like the string contains an array with a single MyStok
object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:
MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
You could also deserialize the array into a list of MyStok
objects, and take the object at index zero.
var myobjList = JSON.Deserialize<List<MyStok>>(sc);
var myObj = myobjList[0];
It looks like the string contains an array with a single MyStok
object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:
MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
You could also deserialize the array into a list of MyStok
objects, and take the object at index zero.
var myobjList = JSON.Deserialize<List<MyStok>>(sc);
var myObj = myobjList[0];
answered Jul 20 '13 at 12:01
dasblinkenlight
609k567711189
609k567711189
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
add a comment |
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
thank you ,It works fine
– sakir
Jul 20 '13 at 12:10
2
2
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
Hmmm. Almost ready to downvote for your first suggestion, but saved by your second.
– spender
Jul 20 '13 at 12:43
14
14
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
@spender I prefer the second way, too, but I think it's nice to give people options: it puts them in a position to make a choice, ultimately resulting in better understanding of the problem.
– dasblinkenlight
Jul 20 '13 at 12:53
add a comment |
For array type Please try this one.
List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
Please See here for details to deserialise Json
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
add a comment |
For array type Please try this one.
List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
Please See here for details to deserialise Json
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
add a comment |
For array type Please try this one.
List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
Please See here for details to deserialise Json
For array type Please try this one.
List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
Please See here for details to deserialise Json
edited Jul 20 '13 at 12:08
answered Jul 20 '13 at 12:07
Janty
1,41321025
1,41321025
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
add a comment |
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
thank you your code works fine as well
– sakir
Jul 20 '13 at 12:29
2
2
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
There is a open parenthese that is missing in your code...
– Sven Borden
Apr 12 '17 at 8:48
add a comment |
HttpClient webClient = new HttpClient();
Uri uri = new Uri("your url");
HttpResponseMessage response = await webClient.GetAsync(uri)
var jsonString = await response.Content.ReadAsStringAsync();
var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
add a comment |
HttpClient webClient = new HttpClient();
Uri uri = new Uri("your url");
HttpResponseMessage response = await webClient.GetAsync(uri)
var jsonString = await response.Content.ReadAsStringAsync();
var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
add a comment |
HttpClient webClient = new HttpClient();
Uri uri = new Uri("your url");
HttpResponseMessage response = await webClient.GetAsync(uri)
var jsonString = await response.Content.ReadAsStringAsync();
var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
HttpClient webClient = new HttpClient();
Uri uri = new Uri("your url");
HttpResponseMessage response = await webClient.GetAsync(uri)
var jsonString = await response.Content.ReadAsStringAsync();
var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
answered Apr 25 '17 at 9:43
Aditi_Systematix
735
735
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
add a comment |
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
This doesn't really add any value to the question or the other answers.
– infl3x
Apr 25 '17 at 10:26
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
this will apply only if you have HttpClient Call I marked as the answer is useful Cause the last line has the answer which is Deserialize it as a list of the class JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
– khaled Dehia
Jul 3 '17 at 17:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17762032%2fcannot-deserialize-the-current-json-array-e-g-1-2-3-into-type%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown