【发布时间】:2022-01-05 01:18:28
【问题描述】:
我调用 API 的方式与调用 API 的方式相同。响应是我所期望的,除了我使用过的所有其他 API 之外,它返回的 XML 字符串很容易从中获取数据。这个特定的 API 似乎返回响应并将响应数据放入对象中。这是我在 C# 中调用 API 的方式...
KeyFieldsAPI.PS_API_KeyFields_V2 KeyFieldsAPI = new KeyFieldsAPI.PS_API_KeyFields_V2();
object KFAPI = KeyFieldsAPI.GetKeyFields(KAccount_Number, KCourier, KService, "", InventoryCodeList);
我可以遍历 KFAPI 对象并将上层字段响应放入变量中,方法是:
foreach (PropertyInfo property in KFAPI.GetType().GetProperties())
{
PropName = property.Name.ToString();
PropType = property.GetType().ToString();
PropValue = property.GetValue(KFAPI, null).ToString();
DataRow dr = ITAB_KFHEADER.NewRow();
dr["Name"] = PropName;
dr["Value"] = PropValue;
ITAB_KFHEADER.Rows.Add(dr);
}
但是,其中两个字段似乎是数组,如此处所示... image of watch values box
我需要从 NeedDate_Item 字段中提取数据,该字段似乎是一个数组,其中包含 3 个索引行数据作为该对象的一部分。谁能建议我如何从这个作为嵌入式数组一部分的 API 响应对象中提取数据?提前感谢大家。
【问题讨论】:
-
响应对象是 JSON 吗?
-
否,响应是 XML 字符串。我想到了。如果我更改代码行以调用 API 从 object 到 var,如下所示:
codevar KFAPI = KeyFieldsAPI.GetKeyFields(KAccount_Number, KCourier, KService, "", InventoryCodeList);code然后它允许我获取像这样的数据: [code]foreach (var NDdate in KFAPI.NeedDate_Item) { *** 在这里工作*** }[/code]