Listbox to Json item

Hi,

I am using the sample code of Json item.
I am trying to convert Listbox row into Json item

Var Person As New JSONItem

Person.Value("no") = "auto"
Person.Value("dt") = "09/03/2022 00:00"
Person.Value("locCode") = "ASBH"
Person.Value("custCode") = "RTL"
Person.Value("ptypeCode") = "EDC"
Person.Value("ptermCode") = "CASH"
Person.Value("cashier") = "100"
Person.Value("remark") = "test API"
Person.Value("sourceTransId") = ""
Person.Value("incTax") = "true"

Var Kids As New JSONItem

dim i as integer
for i = 0 to Listbox1.ListCount-1
  Kids.Add("itemCode"+":"+Listbox1.cell(i,0))
next
Kids.RemoveAt(2)
Person.Value("items") = Kids

Person.Compact = True
Var s As String = Person.ToString

so far its working, but there is a quotation symbol missing in this line,

for i = 0 to Listbox1.ListCount-1
  Kids.Add("itemCode"+":"+Listbox1.cell(i,0))
next

the result that I am expecting is,
"itemCode": "AS000202",

but I got
itemCode: AS000202

is there any better simple way to convert listbox row into Json.

thanks
arief

I think you want to add a JSON object to your array. You are just adding text. Try something like this in your For loop:

Var kid As New JSONItem
kid.Value("itemCode") = ListBox1.Cell(i, 0)
Kids.Add(kid)

yes, thanks its works,
but the array bracket is not shown, I want it displays as an array.

I got the result like,

{
    "no": "auto",
    "dt": "09/03/2022 00:00",
    "locCode": "ASBH",
    "custCode": "RTL",
    "ptypeCode": "EDC",
    "ptermCode": "CASH",
    "cashier": "100",
    "remark": "test API",
    "sourceTransId": "",
    "incTax": "true",
    "items": {
        "itemCode": "AS000205",
        "description": "orange",
        "qty": "2"
    }
}

the others items from listbox is not showing

expecting the result like,

"no": "auto",
	"dt": "09/03/2022 00:00",
	"locCode": "ASBH",
	"custCode": "RTL",
	"ptypeCode": "EDC",
	"ptermCode":"CASH",
	"cashier": "100",
	"remark": "test API",
	"sourceTransId": "",
    "incTax":"true",
	"items": [{
		"itemCode": "AS000202",
		"description": "apple",
		"qty": 1,	
	},{
		"itemCode": "AS000203",
		"description": "mango",
		"qty": 1,
	},{
		"itemCode": "AS000204",
		"description": "grape",
		"qty": 1,
	},{
		"itemCode": "AS000205",
		"description": "orange",
		"qty": 1,
	}],

here are the modified code,

Var Person As New JSONItem

Person.Value("no") = "auto"
Person.Value("dt") = "09/03/2022 00:00"
Person.Value("locCode") = "ASBH"
Person.Value("custCode") = "RTL"
Person.Value("ptypeCode") = "EDC"
Person.Value("ptermCode") = "CASH"
Person.Value("cashier") = "100"
Person.Value("remark") = "test API"
Person.Value("sourceTransId") = ""
Person.Value("incTax") = "true"

Var Kids As New JSONItem

'Listbox data

'AS000202    apple    1
'AS000203    mango    2
'AS000204    grape    3
'AS000205    orange   2

dim i as integer
for i = 0 to Listbox1.ListCount-1
  kids.Value("itemCode") =Listbox1.cell(i,0)
  kids.Value("description") =Listbox1.cell(i,1)
  kids.Value("qty") =Listbox1.cell(i,2)
next
Person.Value("items") = Kids

Person.Compact = True
Var s As String = Person.ToString

JSONDataArea.Text = s

JSONList.RemoveAllRows
ShowJSONObject(person)

any helps?

thnaks
arief