【c# – Json.NET不同的json结构,基于枚举值】教程文章相关的互联网学习教程文章

MVC3不能正确识别JSON中的Enum枚举值【代码】【图】

一、背景在MVC3项目里,如果Action的参数中有Enum枚举作为对象属性的话,使用POST方法提交过来的JSON数据中的枚举值却无法正确被识别对应的枚举值。二、Demo演示为了说明问题,我使用MVC3项目创建Controller,并且创建如下代码演示://交通方式枚举publicenum TrafficEnum{ Bus = 0,Boat = 1,Bike = 2,}publicclass Person{publicint ID { get; set; }publicTrafficEnum Traffic { get; set; }}publicclass DemoController : Cont...

c#-枚举属性,Web API,JSON反序列化和错别字【代码】

假设我们有一个像这样的课程:public class Person {[JsonConstructor]public Person(string name, DayOfWeek bornOnDay) => (Name, BornOnDay) = (name, bornOnDay);public string Name { get; protected set; }public DayOfWeek BornOnDay { get; protected set; } }还有一个这样的端点:[HttpPost] [Route("api/people")] public IHttpActionResult PostPerson([FromBody]List<Person> people) {// whatever }我注意到,如果我在...

Java:将包含枚举的对象转换为Json对象【代码】

我使用org.json库将Object转换为Json格式.请检查以下代码段.public enum JobStatus implements Serializable{INCOMPLETE,INPROGRESS,ABORTED,COMPLETED }public class Job implements Serializable {private string id;private JobStatus status;... }...// Create Job Object Job job = new Job("12345", JobStatus.INPROGRESS);// Convert and print in JSON format System.out.println(new JSONObject(job).toString());它显示如...

c# – 如何防止Json.NET将枚举转换为字符串?【代码】

以下课程public class RequestSections : RequestBase {public RequestSections(Command c, Dictionary<SectionIdentifier, BigInteger> v) : base(c){VERSIONS = v;}public Dictionary<SectionIdentifier, BigInteger> VERSIONS { get; set; } }使用JSON.NET序列化为JSON并生成以下JSON输出:{"VERSIONS": {"Photos": 901,"Music": 902},"CMD": 43 }问题是SectionIdentifier是枚举,但JSON.NET将它们转换为字符串.public enum Sect...

javascript – 如何将枚举数组序列化为Json字符串数组?【代码】

参见英文答案 > Serialize a container of enums as strings using JSON.net 2个基于迭戈在这个问题中最高投票回答的未答复评论: JSON serialization of enum as string 所以对于一个枚举:public enum ContactType {Phone = 0,Email = 1,Mobile = 2 }而对于例如.财产://could contain ContactType.Phone, ContactType.Email, ContactType.Mobile IEnumerable<ContactType> AvailableContact...

c# – Json.NET不同的json结构,基于枚举值【代码】

我需要将我的类转换为JSON并使用Json.NET.但我可以有不同的JSON结构,如:{name: "Name",type: "simple1",value: 100 };要么{name: "Name",type: {optional1: {setting1: "s1",setting2: "s2",///etc.},value: 100 };我的C#代码是:public class Configuration {[JsonProperty(PropertyName = "name")]public string Name{ get; set; }[JsonProperty(PropertyName = "type")]public MyEnumTypes Type { get; set; }public OptionalT...