CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class Program
{
public class Item
{
[JsonIgnore]
public string Name { get; set; }
public string Prop1 { get; set; }
}
public static void Main()
{
var items = new List<Item>
{
new Item { Name = "a", Prop1 = "123" },
new Item { Name = "b", Prop1 = "456" },
new Item { Name = "c", Prop1 = "789" }
};
var obj = items.ToDictionary(x=> x.Name, x => x);
var json = JsonConvert.SerializeObject(obj, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
Console.WriteLine(json);
}
}