Saving arrays in JSON

I’m writing an iOS app so I’m using the “new” way of doing JSON. In my method I have the following code:

[code]
Dim pdata As New Xojo.Core.Dictionary
Dim passage As New Xojo.Core.Dictionary
Dim passages() As Xojo.Core.Dictionary
For Each p As AwardClass In c.passages
pdata.Value(“name”) = p.name
pdata.Value(“number”) = p.number.ToText

    passage.Value("passage") = pdata
    
    passages.Append(passage)
  Next
  benefits.Value("passages") = passages
  [/code]

I’m saving an array with 2 members. In the first, name = “High Passage” and number = 1. In the second, name = “Middle Passage” and number = 2. However, the JSON getting generated is:

“benefits”:{“passages”:[{“passage”:{“name”:“Middle Passage”,“number”:“2”}},{“passage”:{“name”:“Middle Passage”,“number”:“2”}}]

The second is overwriting the first and getting duplicated. Can anyone suggest what I’m doing wrong? Thanks!

[code]Dim passages() As Xojo.Core.Dictionary

For Each p As AwardClass In c.passages

Dim pdata As New Xojo.Core.Dictionary
pdata.Value(“name”) = p.name
pdata.Value(“number”) = p.number.ToText

Dim passage As New Xojo.Core.Dictionary
passage.Value(“passage”) = pdata

passages.Append(passage)

Next

benefits.Value(“passages”) = passages[/code]

[quote=246400:@Art Gorski]
The second is overwriting the first and getting duplicated. Can anyone suggest what I’m doing wrong? Thanks![/quote]
You only ever create one then add it many times
Eli’s posted the right fix
Each time through the loop create a new dictionary and add values to it so they are UNIQUE instances

Thanks for the quick reply!