Home > Net >  How to convert JArray to String array?
How to convert JArray to String array?

Time:11-24

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

CodePudding user response:

You can achieve it using .Select(),

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

Output:

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

.net Fiddle

  • Related