【发布时间】:2019-02-11 19:58:56
【问题描述】:
对 VBA 非常陌生。尝试尽可能多地学习。我可以在即时窗口中获得我想要的输出,但是如何将所有这些都移动到我的工作表中?
老实说,我不确定要尝试什么或在哪里尝试。
Option Explicit
Sub JsonMain()
Dim dict
Dim subDict
Dim strLine As String
' Read from file
Dim FilePath As String
FilePath = ThisWorkbook.Path + "\" + "Main.json"
Dim nFile As Integer
Dim strJson As String
nFile = FreeFile
Open FilePath For Input As #nFile
strJson = Input(LOF(nFile), nFile)
Close #nFile
Dim jp As Scripting.Dictionary
Set jp = JsonConverter.ParseJson(strJson)
Dim gameData As Scripting.Dictionary
Set gameData = jp("data")
Dim theseMonsters As Object
Set theseMonsters = gameData("monsters")
Debug.Print "there are " & theseMonsters.Count & " monsters in the profile"
Dim i As Long
Dim monster As Dictionary
Dim monsterName As Variant
Dim monsterDetails As Variant
For Each monsterName In theseMonsters.Keys
Debug.Print "Monster #" & monsterName
Set monsterDetails = theseMonsters(monsterName)
Debug.Print " -- name: " & monsterDetails("class_name")
Debug.Print " -- total level: " & monsterDetails("total_level")
Debug.Print " -- perfection: " & monsterDetails("perfect_rate")
Debug.Print " -- catch number: " & monsterDetails("create_index")
Dim battleStats As Collection
Set battleStats = monsterDetails("total_battle_stats")
Debug.Print " -- battle stats: ";
For i = 1 To battleStats.Count
Debug.Print battleStats.Item(i) & " ";
Next i
Debug.Print ""
' ...
Next monsterName
End Sub
编辑 1:
预期结果将是打印在 A 行中的每个类别的粗体标题,数据在这些标题下的列中向下排列。
这是我在即时窗口中获得的示例输出:
怪物#47103 -- 名称:Monstratos -- 总等级:20 -- 完美:53.763 -- 捕获数:39 -- 战斗数据:218 288 221 198 227 201
我希望 A 行包含这些粗体标题:Monster #、Name、Total Level、Perfection、Catch Number、HP、PA、PD、SA、SD、SPD(Battle Stats 不是标题,而是个人战斗统计数据)。
下面,以这个 mon 为例,将是:47103, Monstratos, 20, 53.763, 39, 218, 288, 221, 198, 227, 201。
【问题讨论】:
-
请包含Json字符串
-
@QHarr 这就是我目前所拥有的。我正在引用这个 JSON:etheremon.com/api/user/…
标签: json excel vba web-scraping