【发布时间】:2019-12-06 20:31:05
【问题描述】:
我正在尝试通过 rest 接收包含 XML 数组的发布请求,如果我单独发布它可以正常工作,但我尝试发布一个数组它说:
第 1 行位置 140 出错。需要元素。
我的目标是能够接收数组或个人并在 SQL 中发布它们。
这是我想要的 XML 格式:如果我可以删除 xmlns 会很好,但我不知道如何:
<ArrayOfT_persons xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/RestDataAccess">
<T_persons>
<Name>jhon</Name>
<DATETIME>2019-07-29T15:51:41.2540564+03:00</DATETIME>
<GRADE>A</GRADE>
<AGE>16</AGE>
</T_persons>
<T_persons>
<Name>Will</Name>
<DATETIME>2019-07-29T15:51:41.2540564+03:00</DATETIME>
<GRADE>C</GRADE>
<AGE>18</AGE>
</T_persons>
</ArrayOfT_persons>
这里是post方法
[ResponseType(typeof(T_persons))]
public async Task<IHttpActionResult> PostT_persons(T_persons t_persons)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.T_persons.Add(t_persons);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (T_personsESExists(t_persons.NAME))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtRoute("DefaultApi", new { id = T_persons.NAME }, t_persons);
}
【问题讨论】: