Trouble with getting a JSON object's property from JSON arry

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
ziltmilt
Dragon
Posts: 331
Joined: Sun Apr 29, 2007 9:28 pm
Contact:

Trouble with getting a JSON object's property from JSON arry

Post by ziltmilt »

Got a relatively simple problem that has me stumped tonight and figured I should post here for help before tearing out my hair.

I've got a property, Skills, and for a selected token, the value of Skills is an array of JSON objects:

Code: Select all


[{"skillName":"Dodge","attribute":"DEX","skillCode":"4D+1"},{"skillName":"Melee Parry","attribute":"DEX","skillCode":"3D+2"}]

Then, I have a function to iterate through this list of skills and then return the skillCode of a matching skillName. I've tested the function up & down several times and it's getting arguments passed to it correctly.

Code: Select all


[h: token = arg(0)]
[h: skillFind = arg(1)]

[h: skillCode = "2D"]
[h: skillName = ""]
[h: skillProp = getProperty("Skills", token)]

[h, foreach(skill, skillProp), CODE:

	{
		[skillName=json.get(skill,"skillName")]
		[skillCode = if(skillName == skillFind, json.get(skill, "skillCode", skillCode))]
		
	}]	


[h: macro.return = skillCode]

So this function is correctly receiving the token ID, it retrieves the Skill property, and it reads the Skill names. But it simply cannot evaluate where, if the first argument is "Dodge", this string equals the skillName value of the first skill JSON object it encounters in the array. Or, I pass "Melee Parry", it doesn't recognize this string equating to the value of skillName for the 2nd object.

Any idears out there where I've goofed on this? Like I said, I am stumped!! Please save my scalp.

ziltmilt
Dragon
Posts: 331
Joined: Sun Apr 29, 2007 9:28 pm
Contact:

Re: Trouble with getting a JSON object's property from JSON

Post by ziltmilt »

Nevermind!! I found it ... 1 misplaced parenthesis!

Sorry for the false alarm

Post Reply

Return to “Macros”