• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Pulling Out Struct Variables

New Here ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

Newbie question here… how do I get / set these values in this (sub)Struct to variables?

struct.gif

In the end, I want to have them set to variables like:

<cfset CategoryID = StructVar>
<cfset CategoryName = StructVar>

Thanks!

Views

166

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

Actually ended up figuring this one out.

I used:

<cfset CategoryID =i.category.id>
<cfset CategoryName =i.category.name>

Since my CFLOOP over this array is:

<cfloop array="#deserialized#" index=“i”>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

I was going to say that it depends upon what you named the struct, but you did, indeed, figure it out.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

LATEST

MrLeG8  wrote

Actually ended up figuring this one out.

<cfset CategoryID =i.category.id>
<cfset CategoryName =i.category.name>

This is correct, but has the disadvantage that you overwrite the values of categoryID and categoryName at every iteration of the loop. If you wanted a more reusable solution, you could do something like

<cfset categoryID=arrayNew(1)>

<cfset categoryName=arrayNew(1)>

<cfloop from="1" to="#arrayLen(deserialized)#" index="n">

    <cfset categoryID=deserialized["category"]["id"]>

    <cfset categoryName=deserialized["category"]["name"]>

</cfloop>

<!--- verify --->

<cfdump var="#categoryID#" >

<cfdump var="#categoryName#" >

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation