Node.js 自适应卡的JSON负载在http请求主体中变得混乱
当试图从请求体获取JSON时,JSON.Parse会混淆JSON元素,因此webchat不会将其识别为自适应卡。。请帮忙 Node.JS代码:Node.js 自适应卡的JSON负载在http请求主体中变得混乱,node.js,botframework,adaptive-cards,Node.js,Botframework,Adaptive Cards,当试图从请求体获取JSON时,JSON.Parse会混淆JSON元素,因此webchat不会将其识别为自适应卡。。请帮忙 Node.JS代码: var msgContent = {}; msgContent = getjson(function(resb){}); var msg = new builder.Message(session) .addAttachment(msgContent); session.endDialog(msg); function getjson(callback
var msgContent = {};
msgContent = getjson(function(resb){});
var msg = new builder.Message(session)
.addAttachment(msgContent);
session.endDialog(msg);
function getjson(callback){
request.JSON = true;
request.post("https://someapi.web.net",
function (error, response, body){
var resb = {};
resb = JSON.parse(body);
console.log(resb);
callback(resb);
});
};
预期JSON:
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [{
"type": "ColumnSet",
"columns": [{
"type": "Column",
"size": 2,
"items": [{
"type": "TextBlock",
"text": "Tell us about yourself...",
"weight": "bolder",
"size": "large"
},
{
"type": "TextBlock",
"text": "We just need a few more details to get you booked for the trip of a lifetime!",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"text": "Don't worry, we'll never share or sell your information.",
"isSubtle": true,
"wrap": true,
"size": "small"
},
{
"type": "TextBlock",
"text": "Your name",
"wrap": true
},
{
"type": "Input.Text",
"id": "myName",
"placeholder": "Last, First"
},
{
"type": "TextBlock",
"text": "Your email",
"wrap": true
},
{
"type": "Input.Text",
"id": "myEmail",
"placeholder": "youremail@example.com",
"style": "email"
},
{
"type": "TextBlock",
"text": "Phone Number"
},
{
"type": "Input.Text",
"id": "myTel",
"placeholder": "xxx.xxx.xxxx",
"style": "tel"
}
]
},
{
"type": "Column",
"size": 1,
"items": [{
"type": "Image",
"url": "https://upload.wikimedia.org/wikipedia/commons/b/b2/Diver_Silhouette%2C_Great_Barrier_Reef.jpg",
"size": "auto"
}]
}
]
}],
"actions": [{
"type": "Action.Submit",
"title": "Submit"
}]
}
收到的JSON:
{'$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
content:
{ actions: [ [Object] ],
body: [ [Object] ],
type: 'AdaptiveCard' },
contentType: 'application/vnd.microsoft.card.adaptive' }
JSON对象在技术上是具有无序属性的对象,因此您看到的是一个特性,而不是一个bug
有关详细讨论,请参阅 从技术上讲,JSON对象是具有无序属性的对象,因此您看到的是一个特性,而不是bug
有关详细讨论,请参阅 使用
console.log(body)
而不是console.log(resb)
。节点在记录对象时默认只输出2级深度,但body
是完整的JSON字符串。@idbehold非常感谢您的回答,但问题不在于[[object]]部分。JSON中元素的顺序变得混乱。不知道为什么webchat在混乱时无法识别它。只有当JSON的格式与预期的JSON中描述的格式相同时,它才会填充卡片。这…很奇怪。在这两种情况下,请看一看:您能否共享复制错误的bot代码?@NilsW,谢谢您的回复。出于某种原因,它开始使用console.log(body)
而不是console.log(resb)
。节点在记录对象时默认只输出2级深度,但body
是完整的JSON字符串。@idbehold非常感谢您的回答,但问题不在于[[object]]部分。JSON中元素的顺序变得混乱。不知道为什么webchat在混乱时无法识别它。只有当JSON的格式与预期的JSON中描述的格式相同时,它才会填充卡片。这…很奇怪。在这两种情况下,请看一看:您能否共享复制错误的bot代码?@NilsW,谢谢您的回复。出于某种原因,它开始起作用了