【发布时间】:2020-06-24 13:34:30
【问题描述】:
我需要创建一个如下所示的发布请求,请求中包含一个嵌套对象。我不确定如何将 "Person": 部分添加到请求本身。我尝试过不同的事情,现在我想我完全想多了。 这是我需要的:
{
"LocationId": 76349
"Date": 07/05/2020
"AppointmentType": "Xray / Casting"
"Person":{
"Lastname":"Smith","Firstname":"John","Gender":"M","Age":26}
}
And here's the last thing I've tried. This fails with "Unable to determine Json object type for type Person
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RestSharp;
using System.IO;
using Newtonsoft.Json.Linq;
using Json.Net;
public class Person
{
public string Lastname { get; set; }
public string Firstname { get; set; }
public string Gender { get; set; }
public int Age { get; set; }
}
JObject jObjectbody = new JObject();
jObjectbody.Add"LocationId", 76349);
jObjectbody.Add("Date", 07/05/2020);
jObjectbody.Add"AppointmentType", "Xray / Casting");
jObjectbody.Add(new Patient
{
Lastname = "Smith",
Firstname = "John",
Gender = "M",
Age = 26
});
我做错了吗?有没有更好的方法?
【问题讨论】:
-
您的 post 请求是什么样的 - 它期望什么类型的对象?