无法在应用程序脚本中 JSON.parse WooCommerce REST API 响应



产品更新通过Woo Rest API效果很好,但我无法解析JSON响应。JSON 字符串响应看起来正确有效,但是当我调用JSON.parse(json);函数时,JSON 对象看起来很混乱。我无法想象Woocommerce返回错误格式的JSON响应。根据 https://jsonformatter.curiousconcept.com/JSON 验证器,响应有效 (RFC 4627(。我不知道为什么JSON.parse()不起作用。

我的代码及其响应

var url = "https://domain.hu/wp-json/wc/v3/products/" + productID + "?consumer_key=" + apiusername + "&consumer_secret=" + apisecretkey;
var options = {
'contentType': 'application/json',
'method' : 'put',
'payload' : APIPayloadObject
};
var response = UrlFetchApp.fetch(url, options);
var json = response.getContentText();

此时,响应项看起来是正确的,但它不是对象:

{
"id": 2624,
"name": "Mofu00e9m Eurosztu00e1r mosdu00f3 csaptelep leeresztu0151 szelep nu00e9lku00fcl?",
"slug": "mofem-eurosztar-mosdo-csaptelep-leereszto-szelep-nelkul",
"permalink": "https://aeco.hu/termek/mofem-eurosztar-mosdo-csaptelep-leereszto-szelep-nelkul/",
"date_created": "2019-03-18T20:48:54",
"date_created_gmt": "2019-03-18T19:48:54",
"date_modified": "2019-08-11T18:40:26",
"date_modified_gmt": "2019-08-11T17:40:26",
"type": "simple",
"status": "publish",
...

如果我运行var APIresponse = JSON.parse(json);变量的内容如下所示:

{upsell_ids=[], featured=false, purchasable=true, grouped_products=[], _links={self=[{href=https://aeco.hu/wp-json/wc/v3/products/2624}], collection=[{href=https://aeco.hu/wp-json/wc/v3/products}]}, tax_status=taxable, catalog_visibility=hidden, type=simple, external_url=, price=7198, meta_data=[{id=32677, value=323, key=supplier_stock_qty}, {id=62052, value=2-3 hét, key=supplier_shipping_time_backorder}, {id=64328, value=, key=_woosea_brand}, {id=64329, value=, key=_woosea_mpn},...

你知道为什么 JSON.parse(( 不起作用吗?谢谢

我犯了一个错误。JSON.parse(( 中没有错误。谢谢。