简体   繁体   中英

Transform JSON Columns into single column JSON request .net

When requesting a JSON GET I receive the following:

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

I would like this to be transformed to one column with the following values instead of four separate columns from the array. c#, .net would be the best choice of programming language.

id
1731950
1764966
1771940
1931966

It is not clear what you are exactly trying to achieve (as per comments). 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

Then you can deserialize a collection to the list of strings:

using Newtonsoft.Json;

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

I assume that your JSON is array of strings.

If you need exactly the string how did you describe, you can make this conversion:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM