2

starting from a JObject I can get the array that interests me:

JArray partial = (JArray)rssAlbumMetadata["tracks"]["items"];

First question: "partial" contains a lot of attributes I'm not interested on. How can I get only what I need?

Second question: once succeeded in the first task I'll get a JArray of duplicated items. How can I get only the unique ones ? The result should be something like

{
'composer': [
                {
                'id': '51523',
                'name': 'Modest Mussorgsky'
                },
                {
                'id': '228918',
                'name': 'Sergey Prokofiev'
                },
        ]
}

Let me start from something like:

[
  {
    "id": 32837732,
    "composer": {
      "id": 245,
      "name": "George Gershwin"
    },
    "title": "Of Thee I Sing: Overture (radio version)"
  },
  {
    "id": 32837735,
    "composer": {
      "id": 245,
      "name": "George Gershwin"
    },
    "title": "Concerto in F : I. Allegro"
  },
  {
    "id": 32837739,
    "composer": {
      "id": 245,
      "name": "George Gershwin"
    },
    "title": "Concerto in F : II. Adagio"
  }
]
1
  • You should include the JSON you have and what you expect to get. That will help people to help you Commented Apr 9, 2017 at 20:07

1 Answer 1

1

First question:

How can I get only what I need?

There is no magic, you need to read the whole JSON string and then query the object to find what you are looking for. It is not possible to read part of the JSON if that is what you need. You have not provided an example of what the data looks like so not possible to specify how to query.

Second question which I guess is: How to de-duplicate contents of an array of object?

Again, I do not have full view of your objects but this example should be able to show you - using Linq as you requested:

var items = new []{new {id=1, name="ali"}, new {id=2, name="ostad"}, new {id=1, name="ali"}};
var dedup = items.GroupBy(x=> x.id).Select(y => y.First()).ToList();
Console.WriteLine(dedup);
Sign up to request clarification or add additional context in comments.

1 Comment

No more comments ... Please help ! Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.