Answer the question
In order to leave comments, you need to log in
json to c# class
Guys, in short, this JSON caught my eye. I don't even know how to represent it as a class in C#
[
"is a good for child?",
[
[
" what is a good pet for a child",
0,
[
8,
30
]
],
[
" how long is a child 's passport good for",
0,
[
8,
30
]
],
[
" what is a good first pet for a child",
0,
[
8,
30
]
],
[
"is a rabbit a good pet for a child",
0,
[
8,
30
]
]
],
{
"t": {
"bpc": false,
"tlw": false
},
"q": "ul2-5osqijK9Cm5xhyiRfRuPxEk "",
"j": "g"
}
]
Answer the question
In order to leave comments, you need to log in
Not valid json. In general, do a copy / paste here, the service will give you the models you need.
in this form, it is not very readable, to be honest, it’s better to have a piece of code or format it as code or somewhere on paste.org.ru/etc…
Perhaps I misunderstood the question, but if using Newton is not important, then your json is easily deserialized like this:
var result = new JavaScriptSerializer().DeserializeObject(jsonString);
Get an object of type object[], where
object[0] is the string “is a good for child?”
object[1] - array of arrays of strings/numbers
object[2] - dictionary for :{"t": {{"bpc": false,"tlw": false},"q": "ul2-5osqijK9Cm5xhyiRfRuPxEk","j ': 'g'}
Using the JavaScriptSerializer class from System.Web.Extensions
You should have something like these classes:
public class InnerObject
{
public string InnerQuestion{get;set;}
public int Number{get;set;}
public List<int> Numbers{get;set;}
}
public class OuterObject // этот класс - представление json объекта
{
public string OuterQuestion{get;set;}
public List<InnerObject> ListOfObjects{get;set;}
public Dictionry<string, object> Dict{get;set;} // тут не уверен т.к. не знаю возможно ли повторение ключей, в более общем случае используйте Dictionry<object, object>
}
//в исполняемой среде :
var jss = new JavaScriptSerializer();
OuterObject object = jss.Deserialize<OuterObject>(json_data);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question