Десериализация Json с двумя массивами - C#
Формулировка задачи:
Есть файл в который записывается массив юзеров в формате Json (записанно два раза)
Когда питаюсь десериализовать , выдает
Не может десериализовать второй массив юзеров.
Сериализация Десериализация Как решить проблему?
[
{
"Id": 1,
"Name": {
"First": "***",
"Last": "***"
},
"Home": {
"Country": "***",
"Region": "***",
"City": "***",
"Street": "***",
"Apartment": "****"
},
"Info": {
"Birth": "***"
},
"Contact": {
"Email": "***",
"Skype": "***",
"Site": "***"
},
"Authentification": {
"Email": "***",
"Password": "***"
}
},
{
"Id": 2,
"Name": {
"First": "***",
"Last": "***"
},
"Home": {
"Country": "***",
"Region": "***",
"City": "***",
"Street": "***",
"Apartment": "***"
},
"Info": {
"Birth": "***"
},
"Contact": {
"Email": "***",
"Skype": "***",
"Site": "***"
},
"Authentification": {
"Email": "***",
"Password": "***"
}
}
]
[
{
"Id": 1,
"Name": {
"First": "***",
"Last": "***"
},
"Home": {
"Country": "***",
"Region": "***",
"City": "***",
"Street": "***",
"Apartment": "***"
},
"Info": {
"Birth": "***"
},
"Contact": {
"Email": "***",
"Skype": "***",
"Site": "***"
},
"Authentification": {
"Email": "***",
"Password": "***"
}
},
{
"Id": 2,
"Name": {
"First": "***",
"Last": "***"
},
"Home": {
"Country": "***",
"Region": "***",
"City": "***",
"Street": "***",
"Apartment": "***"
},
"Info": {
"Birth": "***"
},
"Contact": {
"Email": "***",
"Skype": "***",
"Site": "***"
},
"Authentification": {
"Email": "***",
"Password": "***"
}
}
]
"Newtonsoft.Json.JsonReaderException" в Newtonsoft.Json.dll
Дополнительные сведения: Additional text encountered after finished reading JSON content: [. Path '', line 55, position 0.
public void Save(params User[] user)
{
using (StreamWriter sw = new StreamWriter(_path,true))
{
sw.WriteLine(JsonConvert.SerializeObject(user, Formatting.Indented));
}
}private User[] GetUsers()
{
return JsonConvert.DeserializeObject<User[]>(File.ReadAllText(_path));
}Решение задачи: «Десериализация Json с двумя массивами»
textual
Листинг программы
public class Name
{
public string First { get; set; }
public string Last { get; set; }
}
public class Home
{
public string Country { get; set; }
public string Region { get; set; }
public string City { get; set; }
public string Street { get; set; }
public string Apartment { get; set; }
}
public class Info
{
public string Birth { get; set; }
}
public class Contact
{
public string Email { get; set; }
public string Skype { get; set; }
public string Site { get; set; }
}
public class Authentification
{
public string Email { get; set; }
public string Password { get; set; }
}
public class RootObject
{
public int Id { get; set; }
public Name Name { get; set; }
public Home Home { get; set; }
public Info Info { get; set; }
public Contact Contact { get; set; }
public Authentification Authentification { get; set; }
}