json - Microsoft Excel - 从 JSON 列中获取值
问题描述
我们正在使用 Azure APIM 服务和链接的 App Insights 来获取请求日志以进行分析。
当我们使用 Imperva WAF 时,我们正在通过 App Insights Logs(Analytics)获取 Imperva IP 并在请求标头中获取客户端的 IP。
所以以 csv 格式获取数据,就像这样
"2019-10-06T17:21:20.2264252Z","|key",,"OPTIONS /Endpoint/","https://APIM/query",True,200,"0.3565","<250ms",request,"{""ApimanagementServiceName"":""APIM_name"",""ApimanagementRegion"":""Country"",""HTTP Method"":""OPTIONS"",""API Name"":""API"",""Cache"":""None"",""Request-Incap-Client-IP"":""2a:23c4:1c4c:6c00:a458_IP""}","{""Client Time (in ms)"":0,""Response Size"":334,""Request Size"":0}","OPTIONS /EndPoint/",Key,,,,,,,PC,,,"0.0.0.0",,,"Country",,"APIM Country","APIM Country","key","App Insights","key","apim:0.81.21.0","key",1
现在我想从“Request-Incap-Client-IP”元素中提取 IP,该元素以 JSON 格式存储,从“ApimanagementServiceName”开始。
我在网上查看了帮助,都在谈论宏,自定义代码。
在我看来,excel 应该具有解析 json 并从特定列中获取值的功能,我的意思是解决方案应该简单明了。
解决方案
使用该自定义库来解析/读取/写入 JSON 文件和流
https://github.com/VBA-tools/VBA-JSON
Dim fso As New FileSystemObject
Dim JsonTS As TextStream
Dim Json As Dictionary
Dim JsonText As String
Set JsonTS = fso.OpenTextFile("yourfile.csv", ForReading)
JsonText = JsonTS.ReadAll
JsonTS.Close
'process the string to isolate JSON part of your CSV using Split/regexp
Set Json = JsonConverter.ParseJson(JsonText)
然后你可以像这样检索值:
Dim ipValue as String
ipValue = Json("Request-Incap-Client-IP")
推荐阅读
- r - 轻松切换按哪些列排序
- byte-buddy - 在 ByteBuddy 中创建数组的 TypeDescryption
- image - 如何在 GIMP 2.10 中编写一个 python 脚本,将当前图像分割成图块,然后将它们保存到单个文件中?
- r - 通过合并 R 中的两列来重塑大型数据框
- python - numpy用填充调整n维数组的大小
- sceneview - 带有 SceneKit 的选项键修饰符 allowCameraControl
- android - 使用 firebaseui:firebase-ui-firestore 构建发布 APK 时出现问题
- javascript - 如果我调用 child.listen(),为什么 Typescript 从父类中调用覆盖的子方法?
- python - 如何通过 importlib 加快导入变量命名模块?
- awk - AWK 从另一个文件的列表中搜索文件并格式化输出