如何修复错误822“ json”意外令牌?

时间:2019-05-20 14:58:59

标签: json vba api shopify

我有一个VBA文件,该文件已经使用POST to API函数工作了多年,可以在Shopify上创建产品。它突然出于未知原因停止工作,大约在2019年4月15日停止工作。它给出了以下错误:

  

“错误”:“ 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"] }]
}}

谢谢!

Youri

2 个答案:

答案 0 :(得分:0)

您提供的第一个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"]
        }]
    }
}
}
}

尝试删除最后两个大括号

答案 1 :(得分:0)

感谢您的回复

@David:我看过链接PHPDeployer,但是我不明白在VBA代码中必须在何处以及如何使用“ X-Shopify-Access-Token”,如果将其添加到objHTTP.setRequestHeader?这是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