0

我正在尝试解析自适应卡,但parsedCard变量是undefined.

let cardObject = $.parseJSON('{"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","type":"AdaptiveCard","version":"0.5","speak":"<s>TheforecastforSeattleJanuary20ismostlyclearwithaHighof51degreesandLowof40degrees</s>","body":[{"type":"Container","items":[{"type":"TextBlock","text":"Seattle,Washington-January20,7:30AM","isSubtle":true}]},{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","size":"auto","items":[{"type":"Image","url":"http://messagecardplayground.azurewebsites.net/assets/MostlyCloudy-Square.png","size":"small","horizontalAlignment":"center"}]},{"type":"Column","size":"auto","items":[{"type":"ColumnSet","columns":[{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"42","size":"extraLarge"}]},{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"°F","weight":"bolder"}]}]},{"type":"TextBlock","text":"MostlyClear","isSubtle":true}]},{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"Hi51"},{"type":"TextBlock","text":"Lo40"}]}]}]}]}');
let adaptiveCard = new AdaptiveCards.AdaptiveCard();
let parsedCard = adaptiveCard.parse(cardObject);
let htmlElement = parsedCard.render();
4

1 回答 1

0

我相信该parse方法不会返回任何东西。尝试以下操作:

let cardObject = $.parseJSON('{"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","type":"AdaptiveCard","version":"0.5","speak":"<s>TheforecastforSeattleJanuary20ismostlyclearwithaHighof51degreesandLowof40degrees</s>","body":[{"type":"Container","items":[{"type":"TextBlock","text":"Seattle,Washington-January20,7:30AM","isSubtle":true}]},{"type":"Container","items":[{"type":"ColumnSet","columns":[{"type":"Column","size":"auto","items":[{"type":"Image","url":"http://messagecardplayground.azurewebsites.net/assets/MostlyCloudy-Square.png","size":"small","horizontalAlignment":"center"}]},{"type":"Column","size":"auto","items":[{"type":"ColumnSet","columns":[{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"42","size":"extraLarge"}]},{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"°F","weight":"bolder"}]}]},{"type":"TextBlock","text":"MostlyClear","isSubtle":true}]},{"type":"Column","size":"auto","items":[{"type":"TextBlock","text":"Hi51"},{"type":"TextBlock","text":"Lo40"}]}]}]}]}');
let adaptiveCard = new AdaptiveCards.AdaptiveCard();
adaptiveCard.parse(cardObject);
let htmlElement = adaptiveCard.render();
于 2017-06-01T11:45:13.377 回答