簡體   English   中英

將 JSON 列轉換為單列 JSON 請求 .net

[英]Transform JSON Columns into single column JSON request .net

請求 JSON GET 時,我收到以下信息:

[
  [ "1731950",
   "1764966",
   "1771940",
   "1931966" ]

我希望將其轉換為具有以下值的一列,而不是數組中的四個單獨的列。 c#、.net 將是編程語言的最佳選擇。

id
1731950
1764966
1771940
1931966

目前尚不清楚您到底想要實現什么(根據評論)。 You can use Json.NET framework, install it into your .NET project through the Nuget Package Manager or through the Package Manager Console typing:

PM> Install-Package Newtonsoft.Json

然后您可以將集合反序列化為字符串列表:

using Newtonsoft.Json;

private static List<string> GetListOfIds(string jsonResponse)
{
    return JsonConvert.DeserializeObject<List<string>>(jsonResponse);
}

我假設您的 JSON 是字符串數組。

如果您確切需要您描述的字符串,您可以進行以下轉換:

var records = GetListOfIds(jsonResponse);
records.Insert(0, "id");
var output = string.Join(Environment.NewLine, records.ToArray());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM