Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert object array string to list string

I have object value

{[
  "Temp",
  "Humidity"
]}  

I want to Convert it to list string
I try

var res= (List<string>)value ;
var res1= value.OfType <List<string>>().ToList();

but it return null

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

(Would be mess in a comment).
If that is coming in as a string, then you could use Newtonsoft from nuget to convert. ie:

var str = @"{[
  ""Temp"",
  ""Humidity""
]}  ";
var json = str.Trim(new char[] { ' ', '{', '}'});
var strlist = JsonConvert.DeserializeObject<List<string>>(json);

EDIT: Along the comments, you say it is a Newtonsoft.Json.Linq.JArray, then this would do:

var lstString = JsonConvert.DeserializeObject<List<string>>(myObject.ToString());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading