[英]JSON Serialize array returns NULL in JSON string
我正在建立這樣的JSON模型
JObject issue_model = JObject.FromObject(new
{
labels = new[] { "import", "automation"}
}
下面的代碼進行序列化
string request_json = JsonConvert.SerializeObject(issue_model,
Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
但是當我嘗試從諸如
list<string> lp_list = new list<string>();
//lp_list contains a list of string values
string[] lp_labels = lp_list.ToArray();
JObject issue_model = JObject.FromObject(new
{
labels = jira_labels
}
我得到了JSON作為
"labels": [
[
null,
null
]
]
但我期望這個json為
“ labels”:{“ import”,“ automation”}
我怎樣才能使陣列序列化正確
我在控制台應用程序中修改了您的代碼。
List<string> lp_list = new List<string>();
lp_list.Add("import");
lp_list.Add("automation");
//lp_list contains a list of string values
//string[] lp_labels = lp_list.ToArray();
JObject issue_model = JObject.FromObject(new
{
labels = lp_list
});
Console.WriteLine(issue_model);
希望它能回答您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.