C# c语言中数据列表与自适应卡列表的动态绑定#
我有一个数据类文件列表,我想在botframeworkv4中使用c#动态绑定到自适应卡 我试过以下方法:C# c语言中数据列表与自适应卡列表的动态绑定#,c#,json,botframework,C#,Json,Botframework,我有一个数据类文件列表,我想在botframeworkv4中使用c#动态绑定到自适应卡 我试过以下方法: mycsfile.cs private asynch Task < DialogTurnResult > GetDynamicAdaptiveCard(WaterfallstepContext stepContext, CancellationToken cancellationToken) { //This is my json file where am having
mycsfile.cs
private asynch Task < DialogTurnResult > GetDynamicAdaptiveCard(WaterfallstepContext stepContext, CancellationToken cancellationToken) {
//This is my json file where am having all the data
string json = File.ReadAllText("path of json file where I have list of data");
JObject o = JObject.Parse(json);
JArray a = (JArray) o["Info"];
//converting json data to list of class
IList < InfoListClass > list = a.ToObject < IList < InfoListClass >> ();
//This is my json file where am having adaptive card
string json1 = File.ReadAllText("path of json file where I have adaptive card");
JObject o1 = JObject.Parse(json1);
JArray a1 = (JArray) o1["body"];
foreach(var item in InfoListClass) {
((JObject) body[0])["text"] = item.name;
}
Attachment attachment = new Attachment() {
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(json.ToString()),
};
return await stepContext.PrompAsynch(nameof(TextPrompt), new PromptOptions() {
Prompt = new Activity {
Type = ActivityTypes.Message,
Attachments = new List < Attachment > {
attachment
},
AttachmentLayout = AttachmentLayoutTypes.Carausel
},
RetryPrompt = MessageFactory.Text("Please"), cancellationToken);
}
输出:我应该得到多张卡片,因为我的类文件中有多个数据,但我只得到一张具有最后列表值的卡片。
有人能告诉我如何获得多张不同值的自适应卡吗?有人能帮我吗。
提前感谢。欢迎来到Stack Overflow。请看一下方便的指南,看看您可以采取哪些步骤更快地获得更好的答案:您的C#代码存在许多问题,这些问题会阻止它编译。
body
在哪里声明?我怀疑你在写这个问题时改变了很多东西,所以我们没有看到你的实际代码,这意味着在你修复之前我们无法帮助你。在粘贴到此处之前,请尝试创建并测试它,以确保它正常工作。您是否看过解释如何进行模板制作的自适应卡文档?欢迎来到堆栈溢出。请看一下方便的指南,看看您可以采取哪些步骤更快地获得更好的答案:您的C#代码存在许多问题,这些问题会阻止它编译。body
在哪里声明?我怀疑你在写这个问题时改变了很多东西,所以我们没有看到你的实际代码,这意味着在你修复之前我们无法帮助你。在粘贴到此处之前,请尝试创建并测试它,以确保它正常工作。您是否看过解释如何进行模板制作的自适应卡文档?
{
"type":"AdaptiveCard",
"body":[
{
"type":"TextBlock",
"size":"Medium",
"weight":"Bolder"
"text":"ABC"//This property I am trying to change with my class property in c#
},
{
"type":"ColumnSet",
"columns":[
{
"type":"Column",
"items":[
{
"type":"Image",
"style":"Person",
"url":"boy picture path"// This one also I wanted to chnge with a other picture from c# by class property
"size":"small"
}
],
"witdh":"auto"
},
{
"type":"Column",
"weight":"Bolder",
"text":"Dr"//Thsi will also change from c#,
"wrap":true
}
]
]
}