本文介绍了将字符串数组转换为JArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组
var ids = new string[]
{
"1408576188",
"1750854738",
"100001058197465"
};
我想将此字符串数组作为json数组传递给API.目前,API 不能接受来自:
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);
因此,我确定可以通过将ids
数组转换为JArray
对象来使用API.
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));
如您所见,我在这里进行了两项操作,首先我序列化ids
数组,然后将结果解析为JArray
.有什么方法可以将我的ids
数组直接转换为JArray
对象?
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?
推荐答案
您是否尝试过FromObject
方法:
var array = JArray.FromObject(ids);
这篇关于将字符串数组转换为JArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!