这些是我的课程:
public class RequestEntity
{
public int Category { get; set; }
public List<string> Types { get; set; }
public List<Parameters> parameters { get; set; }
}
public class Parameters
{
public string Name { get; set; }
public string Type { get; set; }
public bool IsRecent { get; set; }
}
将值设置为:
List<RequestEntity> request = new List<RequestEntity>();
现在我需要创建一个包含2个属性的JObject
。
JObject requestObject = new JObject();
JProperty property1 = new JProperty("Details", request);
JProperty property2 = new JProperty("SpanInDays", 10);
requestObject.Add(property1);
requestObject.Add(property2);
第JProperty property1 = new JProperty("Details", request);
行给出了以下错误。
Could not determine JSON object type for type DAL.Entity.RequestEntity.
答案 0 :(得分:4)
您必须使用某种JToken
作为JProperty
的值(至少在复杂类型的情况下)。您可以使用FromObject
:
JProperty property1 = new JProperty("Details", JToken.FromObject(request));