I'm quite new to JSON, specially serialization and deserialization. I have JSON like this, which i first serialize and put it inside variable. Now i want to get data out of this variable.
{
"timestamp": "2017-06-20 12:12:10",
"categories":
[
{
"name": "Fiction",
},
{
"name": "Roman",
}
]
,
"types":
[
{
"name": "Long story",
},
{
"name": "Short story",
}
],
"books":
[
{
"title": "Song of ice and fire",
"bookNumber": "1234567",
"aisle":
[
{
"location": "fiction isle",
},
{
"location": "roman aisle",
}
]
}
]
}
Stored in my var json
** UPDATE 1**
public List<Books> listOfBooks()
{
var bookList = new List<Books>
{
new Books
{
title = "song of ice and fire"
bookNumber = "1234567",
aisle = listOfAisles()
}
};
return bookList;
}
public List<Aisle> listOfAisles
{
var aisleList = new List<Aisle>
{
new Aisle
{
location = "fiction aisle"
}
};
return aisleList;
}
MainProgram registerBooks = new MainProgram();
var obj = new MainProgram
{
Timestamp = "2017-06-20 09:10:55",
Books = listOfBooks(),
listOfAisles = listOfAisles(),
categories = listOfCategories(),
types = listofTypes()
};
var _myJson = new JavaScriptSerializer().Serialize(object);
Books _books = JsonConvert.DeserializeObject<Books>(_myJson);
string _time = _books.Timestamp;
When i debug i get timestamp and put it in _time and it works fine...but when i try to get other items like categories.name, i can't reach those items.
The problem is i may have many List items inside this JSON, not just one...i could have like 100 categories. how to get those items back?
How should i do this?
Thank you!
edit
public class Books
{
public string title {get;set;}
public string bookNumber {get;set;}
public List<aisle> aisles {get;set;}
}
PS - lower/uppercase isn't the issue! it is due translation to english