CSharp · Console
using System;
using System.Data;
using System.Linq;
using System.Xml;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = @"
{
""result"": [
{
""id"": ""1"",
""name"": ""Temp"",
""property"": []
},
{
""id"": ""2"",
""name"": ""Temp2"",
""property"": []
}
]
}";
JObject obj = JObject.Parse(json);
var emptyArrayProperties = obj["result"]
.Children<JObject>()
.SelectMany(jo => jo.Properties())
.Where(jp => jp.Value.Type == JTokenType.Array && !jp.Value.HasValues)
.ToList();
foreach (JProperty prop in emptyArrayProperties)
{
prop.Remove();
}
DataTable table = obj["result"].ToObject<DataTable>();
foreach (DataRow row in table.Rows)
{
foreach (DataColumn col in table.Columns)
{
Console.WriteLine(col.ColumnName + ": " + row[col]);
}
Console.WriteLine();
}
}
}