【发布时间】: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