How to convert JArray to String array?

I have a JArray as below:

[
  {
    "iccid": "1",
    "quota": "500.00 MB"
  },
  {
    "iccid": "2",
    "quota": "500.00 MB"
  },
  {
    "iccid": "3",
    "quota": "500.00 MB"
  }
]

How to convert it into string array of the ICCID?, I expect to have a string array of the ICCID, like: [‘1′,’2′,’3’]

Many thanks

>Solution :

You can achieve it using .Select(),

List<string> result = jArray.Select(x => x.Value<string>("iccid")).ToList();

Output:

["1", "2", "3"]

.net Fiddle

Leave a Reply