繁体   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