如何将 JSON 加载到 AMP 页面?

How to load JSON into AMP page?

我有一个 A​​MP 页面,我需要使其动态化。如何在 AMP 页面中 加载 Json?我的 json AMP 页面内的代码显示“不是有效的 AMP 页面”错误。

请帮忙。

你做不到 - AMP 是静态的 HTML(你只能从生成页面的服务器端添加动态)

要么你可以检查amp-state。有关详细信息,请参阅 https://www.ampproject.org/docs/tutorials/interactivity/remote-data

  <amp-state id="selected">
    <script type="application/json">
      {
        "slide": 0,
        "sku": "1001"
      }
    </script>
  </amp-state>

您也可以使用amp-list

The amp-list component fetches dynamic content from a CORS JSON endpoint. The response from the endpoint contains data, which is rendered in the specified template.