【发布时间】:2019-11-23 23:48:49
【问题描述】:
您好,我在 c# 中有以下模型。这些是 Avro 文件。
public ProductMessageEvents GetValue(TestPayload parameter)
{
return new ProductMessageEvents()
{
Metadata = new KafkaProductEvent.Metadata
{
Timestamp = "test",
Environment = "test"
},
Product = new KafkaProductEvent.Product
{
AgeGrading = "test",
KeycodeType = "type1",
FamilyTree = new KafkaProductEvent.FamilyTree
{
Class = new KafkaProductEvent.CodeNamePair
{
Code = "test code",
Name = "test name"
}
},
DssProduct = new KafkaProductEvent.DssProduct
{
DocumentStatus = "active"
}
Options = new Option[]
{
new Option
{
PrimaryColour = new CodeNamePair
{
Name = "White",
},
SecondaryColour = new CodeNamePair
{
Name = "red",
}
},
new Option
{
PrimaryColour = new CodeNamePair
{
Name = "White",
}
},
},
Version = "latestVersion"
};
}
}
如果我尝试访问以下值,它会起作用。
object ageGrading = ((GenericRecord)response.Message.Value["Product"])["AgeGrading"];
如果我尝试访问以下值,则会抛出
object familyTree = ((GenericRecord)response.Message.Value["Product"])["FamilyTree"]["Class"]["Code"];
它抛出错误Cannot apply indexing with [] to an expression of type object
有人可以帮我找出这个错误吗?任何帮助,将不胜感激。谢谢。
【问题讨论】:
-
嗨。它不工作。谢谢
-
没有人读过异常消息 :( "Cannot apply indexing with [] to an expression of type object" 表示您正在尝试将 [] 索引应用于表达式对象类型
标签: c# apache-kafka avro confluent-platform