-1

I'm trying to save my data using json. I don't know how to get specific object group from a set of json objects.

[
{
  "dateinformation": "2021-10-05:23:01",
  "id": 1,
  "MoveCount": 3,
  "StartPoint": 2322,
  "TotalDist": 2331,
  "SafeDist": 21332,
  "Feed": 2332,
  "EndPoint":23245,
  "Count":1221,

},
{

  "dateinformation": "2021-10-05:26:01",
  "id": 2,
  "MoveCount": 3,     
  "StartPoint": 2322,
  "TotalDist": 2331,
  "SafeDist": 21332,
  "Feed": 2332,
  "EndPoint":23245,
  "Count":1221,
},
{

  "dateinformation": "2021-10-55:03:01",
  "id": 3,
  "MoveCount": 3,
  "StartPoint": 2322,
  "TotalDist": 2331,
  "SafeDist": 21332,
  "Feed": 2332,
  "EndPoint":23245,
  "Count":1221,

}]

is it possible to get/delete a specific object from a bundle of json object by its "id" value?

Jay
  • 1
  • 1
  • welcome to stackoverflow. what have you ***tried yourself*** so far? what problems did you encounter? what have you researched? please **edit** your question to include more information. i recommend [taking the tour](https://stackoverflow.com/tour), as well as reading [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [what's on topic](https://stackoverflow.com/help/on-topic). hint: the _first_ step in "doing something with json" is **always**: deserialise it into the correct data structure. – Franz Gleichmann Oct 06 '21 at 05:41
  • 1
    Thank you for your feedback and advice. I'll try to make a good question next time. – Jay Oct 06 '21 at 06:15
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 10 '21 at 20:47

1 Answers1

1

Do like that

NameSpace will include:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

Here you can replace your id by specificId

 List<Root> myDeserializedClass = JsonConvert.DeserializeObject<List<Root>>(myJsonResponse); // myJsonResponse is My Source Json
        int specificId = 123; // my dynamic
        var specficObject = myDeserializedClass.Where(x => x.id == specificId);

Class for Deserialize your JSON response:

     public class Root
        {
            public string dateinformation { get; set; }
            public int id { get; set; }
            public int MoveCount { get; set; }
            public int StartPoint { get; set; }
            public int TotalDist { get; set; }
            public int SafeDist { get; set; }
            public int Feed { get; set; }
            public int EndPoint { get; set; }
            public int Count { get; set; }
        }

Also, I have noticed your JSON last column comma in last that should not be like that "Count" : 1221,

Waleed
  • 134
  • 5
  • Thank you.!!! This is exactly what I wanted to implement in my project!!. – Jay Oct 06 '21 at 06:18
  • Welcome Glad to hear that! Kindly like my answer if possible that will help me to keep motivated Thanks – Waleed Oct 06 '21 at 06:19