A
A
Andrey2018-11-03 12:46:16
ASP.NET
Andrey, 2018-11-03 12:46:16

How to set the response deserialization scheme in NewTonSoft?

Good afternoon everyone!
Please tell me, I wrote a simple web api that returns a GET request in the form:

[
    "Шляпа",
    "Кепка"
]

Further in the application, I try to deserialize the response using Newtonsoft tools, but my answer does not fit more than one scheme :( On the Newtonsoft website, in their extensive manual, examples, I did not find anything ... Is
it possible to do this at all?
So :
string json2 = @"{['Шляпа','Кепка']}";
string[] fromJson = JsonConvert.DeserializeObject<string[]>(json2);

I get the following error: Invalid property identifier character: [. Path '', line 1, position 1.
Any advice would be welcome! Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2018-11-03
@andrey71

I think that the error is in the line
Everything in curly braces is an object, but you have an array. Try
string json2 = @"['Шляпа','Кепка']";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question