I have a json file that looks like this:
Json
{
"Telephones": [
{
"TapiLine": "XX Line",
"SpeakerList": [
{
"Name": "Office",
"Ip": "192.168.10.204",
"Volume": "5"
},
{
"Name": "Living",
"Ip": "192.168.10.214",
"Volume": "5"
}
]
}
]
}
Class
class Result
{
public List<Telephone> Telephones { get; set; }
public Result()
{
Telephones = new List<Telephone>();
}
}
class Telephone
{
public string TapiLine { get; set; }
public List<Speakers> SpeakerList { get; set; }
public Telephone()
{
SpeakerList = new List<Speakers>();
}
}
class Speakers
{
public string Name { get; set; }
public string Ip { get; set; }
public string Volume { get; set; }
}
What I'd like to do
I have a combination of TapiLine and Ip and I would like to remove that Object with the according Ip from the SpeakerList.
What I have already
foreach (var telephones in json.Telephones.ToArray())
{
if (telephones.TapiLine == tLine.Name)
{
foreach (var speakers in telephones.SpeakerList)
{
if (speakers.Ip == CurrentEditIp)
{
Console.WriteLine("REMOVE ME: " + speakers.Ip + " FROM: " + tLine.Name);
//UNTIL HERE IT'S FINE; THE REST IS JUST GUESSING...
var docsToRemove = new Result
{
Telephones = new List<Telephone>
{
new Telephone
{
TapiLine = tLine.Name,
SpeakerList = new List<Speakers>
{
new Speakers
{
Name = CurrentEditName,
Ip = CurrentEditIp,
Volume = "5"
}
}
}
}
};
json.Remove(docsToRemove); //THIS DOES NOTHING
}
}
}
}
How could I remove the according object from SpeakerList?
Any hint appreciated!