Convert an array of string into JArray

巧了我就是萌 提交于 2019-12-06 17:28:49

问题


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?


回答1:


Did you try the FromObject method:

var array = JArray.FromObject(ids);


来源:https://stackoverflow.com/questions/36370638/convert-an-array-of-string-into-jarray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!