Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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对象的ID匹配的记录列表?_C#_Json - Fatal编程技术网

C# 如何创建与JSON对象的ID匹配的记录列表?

C# 如何创建与JSON对象的ID匹配的记录列表?,c#,json,C#,Json,我将以下JSON对象(SoftwareImageTestPlans)作为API的输入,我正在尝试创建一个记录,记录所有与第SoftwareImageTestPlans\u行的SoftwareImageID匹配的SoftwareImageID=SoftwareImageTestPlans。选择(c=>c.SoftwareImageID==SoftwareImageID)当我稍后尝试检索数据时,它会抛出一个错误,因此似乎不起作用,如何修复此错误 SoftwareImageTestPlans : [

我将以下JSON对象(SoftwareImageTestPlans)作为API的输入,我正在尝试创建一个记录,记录所有与第
SoftwareImageTestPlans\u行的SoftwareImageID匹配的SoftwareImageID=SoftwareImageTestPlans。选择(c=>c.SoftwareImageID==SoftwareImageID)当我稍后尝试检索数据时,它会抛出一个错误,因此似乎不起作用,如何修复此错误

SoftwareImageTestPlans :
[
  {
    "SoftwareImageTestPlanID": 0,
    "SoftwareImageID": 0,
    "SoftwareImage": "string",
    "TestPlanMasterID": 0,
    "TestPlanVersionID": 0,
    "TestPlanName": "string",
    "TCIndexList": "string",
    "TCNamesList": "string"
  },
  {
    "SoftwareImageTestPlanID": 1,
    "SoftwareImageID": 1,
    "SoftwareImage": "string",
    "TestPlanMasterID": 0,
    "TestPlanVersionID": 0,
    "TestPlanName": "string1",
    "TCIndexList": "string1",
    "TCNamesList": "string1"
  },
  {
    "SoftwareImageTestPlanID": 0,
    "SoftwareImageID": 0,
    "SoftwareImage": "string",
    "TestPlanMasterID": 0,
    "TestPlanVersionID": 0,
    "TestPlanName": "string1",
    "TCIndexList": "string1",
    "TCNamesList": "string1"
  }
]
API:


我认为问题在于:

foreach (var SoftwareImageTestPlan in SoftwareImageTestPlans_WithParticularSoftwareImageID)
{
    Console.WriteLine(SoftwareImageTestPlan.SoftwareImageID); //Throw the error mentioned below
}
您正在迭代bool列表,因此在该foreach中,变量SoftwareImageTestPlan的类型为bool,因此它没有SoftwareImageID

为此,您可以将SoftwareImageTestPlans的类型(带有SpecificularSoftwareImageId)更改为SoftwareImageTestPlan的IEnumerable

换线

SoftwareImageTestPlans_WithParticularSoftwareImageID = SoftwareImageTestPlans.Select(c => c.SoftwareImageID == SoftwareImageID);


我认为问题在于:

foreach (var SoftwareImageTestPlan in SoftwareImageTestPlans_WithParticularSoftwareImageID)
{
    Console.WriteLine(SoftwareImageTestPlan.SoftwareImageID); //Throw the error mentioned below
}
您正在迭代bool列表,因此在该foreach中,变量SoftwareImageTestPlan的类型为bool,因此它没有SoftwareImageID

为此,您可以将SoftwareImageTestPlans的类型(带有SpecificularSoftwareImageId)更改为SoftwareImageTestPlan的IEnumerable

换线

SoftwareImageTestPlans_WithParticularSoftwareImageID = SoftwareImageTestPlans.Select(c => c.SoftwareImageID == SoftwareImageID);


在这个链接中检查你的Json,确保它是有效的Json-MethodMan-我已经做过了,非常有效的Json,我也提供了一个示例这与Json无关。当它到达
AddOrUpdate
时,它只是一个对象数组。在这个链接检查你的Json,确保它是有效的Json-MethodMan-我已经做到了,非常有效的Json,我也提供了一个示例这与Json无关。当它到达
AddOrUpdate
时,它只是一个对象数组。
SoftwareImageTestPlans_WithParticularSoftwareImageID = SoftwareImageTestPlans.Where(c => c.SoftwareImageID == SoftwareImageID);