Highlighted

How to grab data through nested loops?

Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

The problem seems to be that it never gets inside the loop in line 13. I'm not sure if that line of code is correct because it's giving me Error in custom script module before it gets inside the loop. I put a plain texts inside the loop and it never gets executed.

<cfoutput>

    <cfset cfData = DeserializeJSON(artDetails)>

    <cfif structKeyExists(cfData, 'data')>

    <cfif not ArrayIsEmpty(cfData.data) >

        <cfloop index="i" from="1" to="#arrayLen(cfData.data)#">

            <!---<cfdump var="#cfData.data.faqChildren.categories#" >--->

            <cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45#" >

            <!---<cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object#" >--->

            <h2>#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object.name.en#(#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subCount#)</h2>

            <p>url_hash: #cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object.url_hash#</p>

            <cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" >

            <ul>

                <cfloop index="p" from="1" to="#arrayLen(cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent)#" >

                    <li>#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent

.object.name#</li>

                </cfloop>

            </ul>

        </cfloop>

        <cfelse>

        <p>No data found for <b>#hash#</b>.

        <p>

    </cfif>

    </cfif>

</cfoutput>

My dump of subcontent at line 11 shows the following and I want to get the name. Any help is much appreciated.

subContent.png

Okay, I found the answer to my question. Replace line 13-15 with the following and now it's giving me the name that I need.

<cfloop collection="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" item="id">

<li>Cell Name: #cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent[id].object.name#</li>

</cfloop>

Views

224

Likes

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

How to grab data through nested loops?

Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

The problem seems to be that it never gets inside the loop in line 13. I'm not sure if that line of code is correct because it's giving me Error in custom script module before it gets inside the loop. I put a plain texts inside the loop and it never gets executed.

<cfoutput>

    <cfset cfData = DeserializeJSON(artDetails)>

    <cfif structKeyExists(cfData, 'data')>

    <cfif not ArrayIsEmpty(cfData.data) >

        <cfloop index="i" from="1" to="#arrayLen(cfData.data)#">

            <!---<cfdump var="#cfData.data.faqChildren.categories#" >--->

            <cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45#" >

            <!---<cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object#" >--->

            <h2>#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object.name.en#(#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subCount#)</h2>

            <p>url_hash: #cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.object.url_hash#</p>

            <cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" >

            <ul>

                <cfloop index="p" from="1" to="#arrayLen(cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent)#" >

                    <li>#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent

.object.name#</li>

                </cfloop>

            </ul>

        </cfloop>

        <cfelse>

        <p>No data found for <b>#hash#</b>.

        <p>

    </cfif>

    </cfif>

</cfoutput>

My dump of subcontent at line 11 shows the following and I want to get the name. Any help is much appreciated.

subContent.png

Okay, I found the answer to my question. Replace line 13-15 with the following and now it's giving me the name that I need.

<cfloop collection="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" item="id">

<li>Cell Name: #cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent[id].object.name#</li>

</cfloop>

Views

225

Likes

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
Oct 06, 2016 0
Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

Okay, I've narrowed down the issues but not sure why it's still having issues.

<cfdump var="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" >

<p>Length: #arrayLen(cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent)# </p>

The dump shows the following so I think there is an array but the output length shows the "Error in custom script module". Any thoughts?

subContent-array.png

Likes

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
Reply
Loading...
Oct 06, 2016 0
Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

I did an IsArray(cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subconten) and it says no. So, if it's not an array then what is it based on the image I've uploaded above?

Likes

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
Reply
Loading...
Oct 06, 2016 0
Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

Okay, so I have a structure instead of an array. How do I retrieve all the name from this structure? I don't want to manually specify each ID in the dot notation to access the value. There must be some more efficient ways to retrieve all the data within a struct.

Likes

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
Reply
Loading...
Oct 06, 2016 0
Engaged ,
Oct 06, 2016

Copy link to clipboard

Copied

Okay, I found the answer to my question. Replace line 13-15 with the following and now it's giving me the name that I need.

<cfloop collection="#cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent#" item="id">

<li>Cell Name: #cfData.data.faqChildren.categories.5798bea791121cc46fd77a45.subcontent[id].object.name#</li>

</cfloop>

Likes

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
Reply
Loading...
Oct 06, 2016 0