Antisociale
New Member
Hello everybody! I'm working through an example with JSON, I have the following question? How can implement a dynamic number of elements?
{
"Version": 1,
"Items": [
{
"Count": 10,
"Name": "Item #1"
},
{
"Count": 2,
"Name": "Item #2"
},
{
"Count": 43,
"Name": "Item #3"
}
],
"ID": "abcdef"
}
In this example, the number of elements in the "ITEMS" group is 3. Unfortunately, I can’t figure out how to make the number of elements not predetermined. Please excuse my English.
{
"Version": 1,
"Items": [
{
"Count": 10,
"Name": "Item #1"
},
{
"Count": 2,
"Name": "Item #2"
},
{
"Count": 43,
"Name": "Item #3"
}
],
"ID": "abcdef"
}
B4X:
Dim Data As Map = CreateMap("Version": 1.00, "ID": "abcdef", _
"Items": Array( _
CreateMap("Name": "Item #1", "Count": 10), _
CreateMap("Name": "Item #2", "Count": 2), _
CreateMap("Name": "Item #3", "Count": 43)))
Dim jg As JSONGenerator
jg.Initialize(Data)
Dim JsonString As String = jg.ToPrettyString(4)
Log(JsonString)
In this example, the number of elements in the "ITEMS" group is 3. Unfortunately, I can’t figure out how to make the number of elements not predetermined. Please excuse my English.