bixby - 如何将 Javascript 对象传递给 Bixby 的操作输出?
问题描述
我正在构建一个搜索动漫报价的应用程序。所以,我有以下数据,它有 331 个对象(我称之为“报价卡”),因此随着我添加越来越多的报价,它也会在将来更新。我遇到的问题是为 JS 的数组项(例如关键字和 imageTag)创建概念。以及作为属性列出的字符名称。只要我能保留类别和关键字数组项,我也愿意更改输出。这些是我的报价卡所必需的
[
{
$id: "Cold_Souls_1",
animeTitle: "Fullmetal Alchemist Brotherhood",
animePoster:{
referenceImage: 'https://qph.fs.quoracdn.net/main-qimg-da58c837c7197acf364cb2ada34fc5fb.webp',
imageTags: ["Grey","Yellow","Blue","Metal Body","Machine", "Robot","Yellow Hair Boy"],
},
animeCharacters:{
"Edward Elric": [
{
quote: "A lesson without pain is meaningless. For you cannot gain something without sacrificing something else in return. But once you have recovered it and made it your own... You will gain an irreplaceable Fullmetal heart.",
keywords: ["lesson", "pain", "return", "meaningless", "gain","sacrificing", "recover"],
category: "Life Lesson"
}
]
}
},....................
]
解决方案
在 Bixby 中,您将对表示 JSON 响应的结构进行建模。
structure (Anime) {
description (The output of your action)
property (title) {
type(viv.core.Text)
visibility (Private)
}
property (poster){
type(AnimePoster)
visibility (Private)
}
property (characters) {
type (AnimeCharacter)
max (Many)
visibility (Private)
}
}
structure (AnimePoster) {
property (referenceImage) {
type (viv.core.Text)
visibility (Private)
}
property (imageTags) {
type (viv.core.Text)
max (Many)
visibility (Private)
}
}
structure (AnimeCharacter) {
property (name) {
type (viv.core.Text)
visibility (Private)
}
property (quote) {
type (viv.core.Text)
visibility (Private)
}
property (keywords) {
type (viv.core.Text)
max (Many)
visibility (Private)
}
property (category) {
type (viv.core.Text)
visibility (Private)
}
}
在您的 javascript 文件中,您处理动漫的 JSON 结构
// listOfAnimes is the JSON object described in the question
var animes = [];
listOfAnimes.forEach((anime) => {
var characterNames = Object.keys(anime.animeCharacters);
var characters = [];
Object.keys(anime.animeCharacters).forEach((key) => {
characters.push({
name: key,
quote: anime.animeCharacters[key][0].quote, // * warning, can be many
category: anime.animeCharacters[key][0].category// * warning, can be many
});
});
animes.push( {
$id: anime.$id,
title: anime.title,
characters: characters,
poster: {
referenceImage: anime.animePoster.referenceImage,
imageTags: anime.animePoster.imageTags
},
});
});
推荐阅读
- c# - 如何从 DataRow.GetChildRows() 返回所有行
- r - 如何让 as.POSIXct 不更改字符串的时区?
- macos - MacOS上的CMAKE交叉编译将MacOS SDK添加到flags.make中的-isysroot
- python - 在 Python 中旋转具有不同结果的第一个元素
- javascript - 将 JavaScript 变量存储在 PHP 变量中以将其用于源页面中的动态元描述
- ios - PrototypeCell 中的 UITextView 在两个 iPhone 模拟器中具有不同的行为
- windows - 坐标计算程序
- sql - 有没有办法在 postgresql 中使用qualify
- laravel - Laravel - 内部服务器错误和禁止访问
- c - C中的分段错误做一个并发服务器