Reputation: 1937
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?
Upvotes: 42
Views: 49017
Reputation: 1038930
Did you try the FromObject
method:
var array = JArray.FromObject(ids);
Upvotes: 100