-4

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

tu pham
  • 7
  • 1

1 Answers1

0

(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());
Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39