【问题标题】:JSON neglect { when POSTJSON 忽略 { 当 POST
【发布时间】:2022-11-17 22:25:33
【问题描述】:

我需要使用 BigCommerce API 发布脚本。 这是尸体

{
  "name": "string",
  "description": "string",
  "html": "string",
  "src": "(function (sCDN, sCDNProject, sCDNWorkspace, sCDNVers) {
    if (
      window.localStorage !== null &&
      typeof window.localStorage === 'object' &&
      typeof window.localStorage.getItem === 'function' &&
      window.sessionStorage !== null &&
      typeof window.sessionStorage === 'object' &&
      typeof window.sessionStorage.getItem === 'function'
    ) {
      sCDNVers =
        window.sessionStorage.getItem('wx_preview_version') ||
        window.localStorage.getItem('wx_preview_version') ||
        sCDNVers;
    }
    window.x= window.x|| {};
    window.x.config = window.x.config || {};
    window.x.config.frontend = window.x.config.frontend || {};
    window.x.config.frontend.cdnhost =
      sCDN + '/get/' + sCDNWorkspace + '/web/' + sCDNVers + '/';
    window.x.config.frontend.vers = sCDNVers;
    window.x.config.frontend.env = sCDNWorkspace;
    window.x.config.frontend.project = sCDNProject;
    window._wx = window._wx || [];
    var f = document.getElementsByTagName('script')[0];
    var j = document.createElement('script');
    j.async = true;
    j.src = window.x.config.frontend.cdnhost + 'sss.js';
    f.parentNode.insertBefore(j, f);
  })(
    'https://xxxx.x-x-x.mybigcommerce.com',
    'x-test-env',
    'live',
    '_'
  );",
  "auto_uninstall": true,
  "load_method": "default",
  "location": "head",
  "visibility": "storefront",
  "kind": "src",
  "api_client_id": "string",
  "consent_category": "essential",
  "enabled": true,
  "channel_id": 1
}

但它回来了

{ “状态”:400, "title": "输入无效", “类型”:“https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes”, “错误”:{}}

好像它发生在'{'

我可以将此脚本发布到头部的任何方法吗?

【问题讨论】:

  • 通过将 { 替换为 \{ 来转义字符串中的这些字符。
  • JSON 中的字符串不能有文字换行符。该 JSON 从何而来?您可能希望使用更好的 JSON 序列化程序来生成 JSON。
  • @HereticMonkey:JSON 不应该要求转义{。新线似乎是这里的问题。

标签: javascript json postman bigcommerce


【解决方案1】:

使脚本一行。 JSON 由于换行而损坏。

【讨论】:

    猜你喜欢
    • 2019-07-12
    • 1970-01-01
    • 2017-11-11
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多