请求JSON GET时,我收到以下消息:
[
[ "1731950",
"1764966",
"1771940",
"1931966" ]
我希望将其转换为具有以下值的一列,而不是数组中的四列。net将是最好的编程语言选择。
id
1731950
1764966
1771940
1931966
目前尚不清楚您到底想要实现什么(根据注释(。您可以使用Json.NET框架,通过Nuget Package Manager或Package Manager控制台将其安装到.NET项目中,键入:
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());