Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JSON中没有数据输出-获取204错误代码_C#_.net_Json - Fatal编程技术网

C# JSON中没有数据输出-获取204错误代码

C# JSON中没有数据输出-获取204错误代码,c#,.net,json,C#,.net,Json,我正在尝试为具有特定订单的特定客户输出付款计划 我不断地发现这个错误: info:Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1] Executing ObjectResult, writing value of type 'null'. 有些事情我做错了,但我不确定是什么。很长一段时间都在寻找解决方案,但运气不佳。我对编程和C语言还不熟悉,所以仍在努力掌握这一点。非常感谢您的帮助和指导 以下是我到目前为止的情

我正在尝试为具有特定订单的特定客户输出付款计划

我不断地发现这个错误:

 info:Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
  Executing ObjectResult, writing value of type 'null'.
有些事情我做错了,但我不确定是什么。很长一段时间都在寻找解决方案,但运气不佳。我对编程和C语言还不熟悉,所以仍在努力掌握这一点。非常感谢您的帮助和指导

以下是我到目前为止的情况:

型号:


好的,在仔细扫描代码之后,我发现问题出在这个方法中

public static RepaymentPlan GetRepaymentPlan(string customerId, string orderId)
您将始终返回
null
,因为您的条件将始终计算为
false
。这适用于任何(可能)编程语言。
if(customerlist==orderlist)
计算两个对象是否相同(它们引用相同的内存地址),它不会计算对象的内容。要查看两个对象是否具有相同的数据,可以使用循环(
for
while
)。但是由于使用了Linq,所以在
FindAll
函数中使用多个条件就足够了

public static RepaymentPlan GetRepaymentPlan(string customerId, string orderId)
{
 var customerlist =_CustomerOrder.FindAll(c => c.CustomerId==customerId && c.orderId==orderId); 
 var pplist= new RepaymentPlan();

 if (customerlist.Any())
 {
     return pplist; 
 }
 return null;
}

此外,您可能希望返回
customerlist.First()
,而不是
pplist
。如果您返回类型为
ReturnmentPlan
的空对象,它可能对您没有帮助。

好的,仔细扫描代码后,我发现问题出在这个方法中

public static RepaymentPlan GetRepaymentPlan(string customerId, string orderId)
您将始终返回
null
,因为您的条件将始终计算为
false
。这适用于任何(可能)编程语言。
if(customerlist==orderlist)
计算两个对象是否相同(它们引用相同的内存地址),它不会计算对象的内容。要查看两个对象是否具有相同的数据,可以使用循环(
for
while
)。但是由于使用了Linq,所以在
FindAll
函数中使用多个条件就足够了

public static RepaymentPlan GetRepaymentPlan(string customerId, string orderId)
{
 var customerlist =_CustomerOrder.FindAll(c => c.CustomerId==customerId && c.orderId==orderId); 
 var pplist= new RepaymentPlan();

 if (customerlist.Any())
 {
     return pplist; 
 }
 return null;
}

此外,您可能希望返回
customerlist.First()
,而不是
pplist
。如果您返回类型为
还款计划的空对象,它可能对您没有帮助。

您正在调用什么URL
204无内容
表示:服务器已成功完成请求,并且响应有效负载正文中没有要发送的其他内容。@Tony我正试图调用此URL,如控制器中所述:“{customerid}/orders/{orderId}/paymentPlan”,据我所见,参数是字符串,因此,类似于
localhost:5000/customers/CustomerABC/orders/ORDER001/paymentPlan
的内容取决于您发出请求的方式,您应该将
FindPaymentPlan
的返回值更改为
ActionResult
JsonResult
是否可能您实际点击了“return null”代码中的语句?您正在调用什么URL
204无内容
表示:服务器已成功完成请求,并且响应有效负载正文中没有要发送的其他内容。@Tony我正试图调用此URL,如控制器中所述:“{customerid}/orders/{orderId}/paymentPlan”,据我所见,参数是字符串,因此,类似于
localhost:5000/customers/CustomerABC/orders/ORDER001/paymentPlan
的内容取决于您发出请求的方式,您应该将
FindPaymentPlan
的返回值更改为
ActionResult
JsonResult
是否可能您实际点击了“return null”代码中的语句?看起来你的代码有点不对劲。我得到了200条回复的字典:
{“choices”:null}
这似乎是你对某事的理解。我得到了200个响应的字典:
{“choices”:null}
public static RepaymentPlan GetRepaymentPlan(string customerId, string orderId)
{
 var customerlist =_CustomerOrder.FindAll(c => c.CustomerId==customerId && c.orderId==orderId); 
 var pplist= new RepaymentPlan();

 if (customerlist.Any())
 {
     return pplist; 
 }
 return null;
}