0

我正在尝试在我的应用程序中实现 Lottie 动画,我正在使用 expo SDK,所以我遵循了关于 expo 的文档,

_loadAnimationAsync = async () => {
let result = await fetch(
  'https://cdn.rawgit.com/airbnb/lottie-react-native/635163550b9689529bfffb77e489e4174516f1c0/example/animations/Watermelon.json'
);

this.setState(
  { animation: JSON.parse(result._bodyText) },
  this._playAnimation
);

};

我收到了 [未处理的承诺拒绝:语法错误:JSON 解析错误:意外的标识符“未定义”]。

结果 ._bodyText 是空的还是未定义的?

4

1 回答 1

0

我只是遇到同样的问题并修复。

修改_loadAnimationAsync应该让它工作。

_loadAnimationAsync = async () => {
let result = await fetch(
  'https://cdn.rawgit.com/airbnb/lottie-react-native/635163550b9689529bfffb77e489e4174516f1c0/example/animations/Watermelon.json'
)
  .then(data => {
    return data.json();
  })
  .catch(error => {
    console.error(error);
  });
this.setState({ animation: result }, this._playAnimation);
};

如果您有兴趣,我也为此问题启动公关。这里

于 2018-05-06T05:59:12.810 回答