为什么会出现“错误:无效的 JSON:意外的令牌”? 这是全新的!

问题描述

enter image description here这是我第一次尝试将代码添加到我的网站中,所以我对整个事情还很陌生......我想要做的是添加“你好吗?在我的网站上了解我们对结帐流程的问题。

具体来说,我在尝试使用来自“shopify 开发人员”的编码说明向我的网站添加主题设置时遇到了问题。在“主题”的配置目录中,单击 settings_schema.json 后,我按照说明在第一个大括号 } 后添加一些代码,但是当我这样做并尝试点击保存时,错误消息“无效的 JSON:意外的令牌”过来。如果有人可以帮助我,将不胜感激!我粘贴在现有代码下面,下面是我试图插入的代码片段。仅供参考,我正在使用 safari。

有人知道吗?

最好的, 科斯莫

现有代码

[
{
"name": "theme_info","theme_name": "Themekit template theme","theme_version": "1.0.0","theme_author": "Shopify","theme_documentation_url": "https:\/\/github.com\/Shopify\/themekit","theme_support_url": "https:\/\/github.com\/Shopify\/themekit\/issues"
}
]

我要插入的新代码

{
"name": "Hear About Us","settings": [
    {
        "type": "text","id": "hau_form_options","label": "Form options","default": "Facebook,Twitter,Google,Instagram,Youtube","info": "Separate each option with a comma"
    },{
        "type": "header","content": "Form validation"
    },{
        "type": "checkbox","id": "hau_form_validation","label": "Enable form validation","default": true
    },{
        "type": "text","id": "hau_error_message","label": "Error message","info": "The error message that is displayed when no selection is made","default": "Please select an option below"
    },"id": "hau_error_message_other","label": "Other field error message","info": "The error message that is displayed when there is no input in the 'Other' field","default": "Please fill the text field below"
    },"content": "Error styling"
    },{
        "type": "color","id": "hau_error_color","label": "Color","default": "#ff0000"
    }
]
},

解决方法

我使用 JSONLint 检查了 JSON,看起来末尾的尾随逗号把它搞砸了。

编辑:我现在看到图像,因为您要将它添加到数组,所以需要在之前添加逗号。

[{
        "name": "theme_info","theme_name": "Themekit template theme","theme_version": "1.0.0","theme_author": "Shopify","theme_documentation_url": "https:\/\/github.com\/Shopify\/themekit","theme_support_url": "https:\/\/github.com\/Shopify\/themekit\/issues"
    },{
        "name": "Hear About Us","settings": [{
                "type": "text","id": "hau_form_options","label": "Form options","default": "Facebook,Twitter,Google,Instagram,Youtube","info": "Separate each option with a comma"
            },{
                "type": "header","content": "Form validation"
            },{
                "type": "checkbox","id": "hau_form_validation","label": "Enable form validation","default": true
            },{
                "type": "text","id": "hau_error_message","label": "Error message","info": "The error message that is displayed when no selection is made","default": "Please select an option below"
            },"id": "hau_error_message_other","label": "Other field error message","info": "The error message that is displayed when there is no input in the 'Other' field","default": "Please fill the text field below"
            },"content": "Error styling"
            },{
                "type": "color","id": "hau_error_color","label": "Color","default": "#ff0000"
            }
        ]
    }
]

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...