如何将Javascript对象传递给Bixby的动作输出?

如何将Javascript对象传递给Bixby的动作输出?,bixby,bixbystudio,Bixby,Bixbystudio,我正在构建一个应用程序,搜索动画引用。所以,我有下面的数据,是331个对象,我称它们为“报价卡”,所以随着我添加越来越多的报价,它也将在将来更新。我遇到的问题是为JS的数组项创建概念,例如关键字和imageTag。以及列为属性的字符名。我也愿意改变输出,只要我能保持类别,关键字数组项目。这些是我的报价卡所必需的 [ { $id: "Cold_Souls_1", animeTitle: "Fullmetal Alchemist Brotherhood", animePo

我正在构建一个应用程序,搜索动画引用。所以,我有下面的数据,是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结构


因此,我发现我需要使用javascript在quote对象中移动角色的名称。但是为什么可见性是私有的呢?visibilityPrivate会对规划者隐藏该属性。这种情况的好处是,您不必为模型创建一堆自定义概念来返回文本、布尔值等基本属性。我阅读了文档,但如果用户要求提醒他们角色名称或节目标题,属性投影是否会有所帮助。在这些情况下,属性投影会很有帮助,因为它会将动画报价卡作为一个整体并输出特定的值。正确,如果您计划将属性用作投影或其他动作的输入,则可以对自定义概念进行建模。我发现使用visibilityPrivate对我的结构建模更快,并首先从操作返回结果。No$无效-在$vivContext中用于表示它是平台提供的对象
// 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
       },

    });

});