用户https://stackoverflow.com/users/478884/tim-williams已经提供了一个很好的脚本来为 Cardano 区块链制作策略 json
但是为了调整现有脚本,我想尝试将 json 的元素分组到一个集合中。
属性应该分组到一个特征:{[]} 集合
Sub live2_json()
Dim jsonFileObject As New FileSystemObject
Dim jsonFileExport As TextStream
Dim i, count As Long
Dim root As Dictionary, k As Dictionary, a As Long
Dim tokenname, name, id, description, madeof, rarity, publisher, series, value, ipfshash, bg, plate, cutlery, napkin, temperature, roommates As String
Dim max_count As Double
While ThisWorkbook.Sheets("Tokens").Cells(2 + i, 1).value <> ""
max_count = 0
max_count = ThisWorkbook.Sheets("Tokens").Cells(2 + i, 1).value
tokenname = ThisWorkbook.Sheets("Tokens").Cells(2 + i, 2).value
Set root = New Dictionary
Set k = New Dictionary
Set properties = New Dictionary
set props = New Collection
root.Add "721", k
k.Add "policy", New Dictionary
Set k = k("policy")
For count = 0 To max_count - 1
'Tokenname
tokenname = ThisWorkbook.Sheets(tokenname).Cells(2 + count, 2).value
k.Add tokenname, New Dictionary
With k(tokenname)
id = ThisWorkbook.Sheets(tokenname).Cells(2 + count, 4).value
'Name
name = ThisWorkbook.Sheets(tokenname).Cells(2 + count, 3).value
.Add "Name", name
.Add "Id", id
End With
k.Add tokenname, properties
properties.Add props
props.Add "prop1", "blue"
props.Add "prop2", "red"
Next
i = i + 1000
Wend
Set jsonFileExport = jsonFileObject.CreateTextFile("C:\1_DEV\BIGjsonExample.json", True)
jsonFileExport.WriteLine (JsonConverter.ConvertToJson(root, Whitespace:=2))
不幸的是,这个集合被添加到 json 的末尾而不是 tokenname 部分。如果我将它放入 for-next 它会粉碎:/
这是我想要构建并用作参考的结构
{
"721": {
"1131301ad4b3cb7deaddbc8f03f77189082a5738c0167e1772233097": {
"CardanoBits4792": {
"image": "ipfs://ipfs/QmRXMuJQnUfrkYASW4Ur2dinTAKQ5mJ41ZspnQjxt3MRw7",
"name": "CardanoBits #4792",
"properties": [
{
"key": "type",
"value": "human"
}
],
"tags": [
"male",
"brown-skin",
"red-shirt",
"ugly-blonde",
"bloody"
]
}
}
}
}