Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an array of string into JArray

Tags:

c#

json.net

I have an array of string

var ids = new string[] {     "1408576188",     "1750854738",     "100001058197465" }; 

I want to pass this array of string as a json array into an API. For now, the API cannot accept the string returned from :

JsonConvert.SerializeObject(ids); 

So I am figuring out that I am able to use the API by turning my ids array into a JArray object.

JArray.Parse(JsonConvert.SerializeObject(ids)); 

As you can see, I am doing a two operation in here, first I serialize the ids array, then I parse the result into JArray. Is there any way to convert my ids array directly into JArray object?

like image 908
hendryanw Avatar asked Apr 02 '16 07:04

hendryanw


1 Answers

Did you try the FromObject method:

var array = JArray.FromObject(ids); 
like image 166
Darin Dimitrov Avatar answered Oct 07 '22 17:10

Darin Dimitrov