我有要在bot框架v4中使用C#动态绑定到自适应卡的数据类文件列表 我在下面尝试过:
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);
}
//我的自适应卡
{
"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
}
]
]
}
输出:我应该获得多张卡片,因为我的班级文件中有多个数据,但是我只获得了一张具有最后一个列表值的卡片。 请有人告诉我如何获得多张具有不同值的自适应卡吗?有人可以帮助我。 预先感谢。