【问题标题】:How to fix error 822 unexpected token at "json"?如何在“json”处修复错误 822 意外令牌?
【发布时间】:2019-05-20 14:58:59
【问题描述】:

我有一个多年来一直使用 POST to API 函数在 Shopify 上创建产品的 VBA 文件。它突然在 2019 年 4 月 15 日左右因不明原因停止工作。它给出了以下错误:

"error": "822: [我的 JSON 字符串] 出现意外标记

这是 JSON 字符串的样子(您可以在本文末尾找到更完整的字符串):

{
  "product": {
    "title": "Lunettes",
    "body_html": "some long text",
    "vendor": "Tom Ford",
    "product_type": "lunettes enfant adolescents",
    "published": false,
    "tags": "some tags",
    "variants": [
      {
        "option1": "default title",
        "price": "199",
        "sku": "1",
        "weight_unit": "g"
      }
    ],
    "options": [
      {
        "name": "title",
        "position": 1,
        "values": [
          "default title"
        ]
      }
    ]
  }
}

我已经尝试过的:

  • 使用正确的 API 密钥和令牌/密码检查 URL

  • 尝试将最新发布的 Shopify API 版本添加到 CURL:2019-04

  • 检查 JSON 字符串的语法(逗号、{ 等)

基本上尝试了我所知道的一切。如果您有任何线索,请提供帮助。

更完整的 Json_String 是:

{"product":{"title":"Lunettes TF5501 ","body_html":"TEXT,<div style=\"text-align: center;\"><img alt=\"Dimensions Lunettes Varionet TF5501 Argent\" src=\"https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795\" style=\"float: none; display: block; margin-left: auto; margin-right: auto;\" /></div><div style=\"overflow-x: auto;\"> <table width=\"100%\"> <tbody><tr style=\"background-color: #98ffaf;\"><td style=\"text-align: center;\">140 mm</td><td style=\"text-align: center;\">54 mm</td><td style=\"text-align: center;\">38 mm</td><td style=\"text-align: center;\">18 mm</td><td style=\"text-align: center;\">145 mm</td></tr></tbody></table></div>","vendor":"Brand","product_type":"lunettes anti lumière bleue","published":false,"tags":"meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent","variants":[{"option1":"default title","price":"199","sku":"tom ford tf5501016","position":1,"grams":"100","inventory_policy":"deny","compare_at_price":"339","fulfillment_service":"logisticien-mavu","inventory_management":"shopify","option_1":"default title","requires_shipping":true,"taxable":true,"inventory_quantity":1,"weight_unit":"g"}],"options":[{"name":"title","position":1,"values":["default title"] }]
}}

谢谢!

你的

【问题讨论】:

  • 通常你可能会意外添加一个被解析器读取的字符并搞砸了,但你不能轻易看到它。此错误不是来自 Shopify,而是源自您的请求代码。仔细检查您的数据是否有奇怪的字符。此外,其他有同样问题的人通过修复他们的标题解决了这个问题。确保你的也是正确的。 community.shopify.com/c/Shopify-APIs-SDKs/…
  • 查看实际代码会有所帮助(无需您的个人凭据)

标签: json vba api shopify


【解决方案1】:

您提供的第一个 JSON(请将其更正为代码块)是正确的,但是在解析更完整的 Json_string 时,您会发现末尾的大括号太多:

{
    "product": {
        "title": "Lunettes TF5501 ",
        "body_html": "TEXT,https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795\" style=\"float: none; display: block; margin-left: auto; margin-right: auto;\" /> 140 mm54 mm38 mm18 mm145 mm",
        "vendor": "Brand",
        "product_type": "lunettes anti lumière bleue",
        "published": false,
        "tags": "meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent",
        "variants": [{
            "option1": "default title",
            "price": "199",
            "sku": "tom ford tf5501016",
            "position": 1,
            "grams": "100",
            "inventory_policy": "deny",
            "compare_at_price": "339",
            "fulfillment_service": "logisticien-mavu",
            "inventory_management": "shopify",
            "option_1": "default title",
            "requires_shipping": true,
            "taxable": true,
            "inventory_quantity": 1,
            "weight_unit": "g"
        }],
        "options": [{
            "name": "title",
            "position": 1,
            "values": ["default title"]
        }]
    }
}
}
}

尝试删除最后 2 个大括号

【讨论】:

  • 您好,谢谢您的回复,抱歉,2 个额外的花括号是错字。我已将它们从第一篇文章中删除。
【解决方案2】:

感谢您的回复

@David:我已经看到链接https://community.shopify.com/c/Shopify-APIs-SDKs/error-gt-822-unexpected-token-at-price-rule/td-p/480430,但我不明白我必须在哪里以及如何在 VBA 代码中使用“X-Shopify-Access-Token”,是否应该将它添加到 objHTTP.设置请求头?这是 API 密钥、密码还是“共享密钥”?

@QHarr:我的发帖参数是:

Dim result As String
Dim objHTTP As Object
Url = "http://API-KEY:PASSWORD@SHOP-NAME.myshopify.com/admin/api/2019-04/products.json"

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

objHTTP.Open "POST", Url, False, "API-KEY", "PASSWORD"
objHTTP.setRequestHeader "Content-Type", "application/json"


objHTTP.send ("json_string")

result = objHTTP.responseText

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    相关资源
    最近更新 更多