Excel VBA读取网址API 类Json数据并写入单元格的方法

示例代码:

  1. Sub Readjson()
  2. Dim http
  3. Dim aa as String
  4. Set http = CreateObject("Microsoft.XMLHTTP")
  5. http.Open "POST", "http://api.xxxx.com", False
  6. http.send ""
  7. If http.Status = 200 Then
  8. aa = http.responseText
  9. MsgBox "成功。"
  10. Else
  11. MsgBox "调用失败,错误代码:" & http.Status
  12. Range("A1").value = aa
  13. End If
  14. End sub

XMLHTTP是一个微软内置方法,可以直接获取API数据。文章源自原紫番博客-https://www.yuanzifan.com/53505.html

这里Http是一个定义的变量,是一个对象。文章源自原紫番博客-https://www.yuanzifan.com/53505.html

该对象的 .responseText方法,是直接返回Json字符串的文章源自原紫番博客-https://www.yuanzifan.com/53505.html

将字符串赋值给变量aa,再把aa写进A1单元格。需要进一步处理,则在AA之中用Js处理Json字符串。文章源自原紫番博客-https://www.yuanzifan.com/53505.html

文章源自原紫番博客-https://www.yuanzifan.com/53505.html 文章源自原紫番博客-https://www.yuanzifan.com/53505.html

站长微信
扫码添加(注明来意)
weinxin
Yuanzifan99
原梓番博客公众号
博客内容精选
weinxin
原梓番博客
 

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证
加载中...