json.append() and empty properties
Posted: Wed Jun 30, 2010 11:18 am
One last query (for now):
I want to store some [wiki]JSON Object[/wiki]s in a [wiki]JSON Array[/wiki] and store the array in a property. I want to be able to add and remove object from the [wiki]JSON Array[/wiki] whenever I like. I am trying to add items using this macro:
The problem that I keep running into is that it is impossible for me to tell whether or not there is already a [wiki]JSON Array[/wiki] assigned to the property. [wfunc]json.type[/wfunc] won't tell me if weaponProperty contains a [wiki]JSON Array[/wiki] or not (returns UNKNOWN regardless of what the value of my property is), and if there is a [wiki]JSON Array[/wiki] already there then the [wfunc]if[/wfunc] statement throws an invalid condition error.
Is there a better mousetrap for this quandary?
I want to store some [wiki]JSON Object[/wiki]s in a [wiki]JSON Array[/wiki] and store the array in a property. I want to be able to add and remove object from the [wiki]JSON Array[/wiki] whenever I like. I am trying to add items using this macro:
Code: Select all
[h:meleeWeaponList = meleeWeaponList()]
[h:weaponList = ""]
[h,foreach(element, meleeWeaponList):
weaponList = listAppend(weaponList, element)]
[h:okay = input(
"selection|" + weaponList + "|Choose a weapon to add|LIST|SELECT=0 VALUE=STRING"
)]
[h,if(okay == 1), code:{
[h:weaponStats = json.get(meleeWeaponList, selection)]
[h:weaponProperty = getProperty("Weapons", getSelected())]
[h:weaponProperty = if(weaponProperty == "", "[]", weaponProperty)]
[h:weaponProperty = json.append(weaponProperty, weaponStats)]
[h:setProperty("Weapons", weaponProperty, getSelected())]
[macro("[email protected]:WFRP"):""]
}]
The problem that I keep running into is that it is impossible for me to tell whether or not there is already a [wiki]JSON Array[/wiki] assigned to the property. [wfunc]json.type[/wfunc] won't tell me if weaponProperty contains a [wiki]JSON Array[/wiki] or not (returns UNKNOWN regardless of what the value of my property is), and if there is a [wiki]JSON Array[/wiki] already there then the [wfunc]if[/wfunc] statement throws an invalid condition error.
Is there a better mousetrap for this quandary?