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

Getting data from an array

Contributor ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

Hi folks. I am trying to get data from an array in a JSON file. I create the variable webhook from the JSON. I need to get the product_ID from the two arrays.  When I dump webhook to a file, it looks like this:

...

line_items:
[array]
1) [struct]
id: 14
image:
[struct]
id: 57
src: https://i0.wp.com/www.blah.com/wp-content/uploads/2022/07/block_logo_round.png?fit=1200%2C1200&ssl=1
meta_data:
[array]
1) [struct]
display_key: _reduced_stock
display_value: 1
id: 155
key: _reduced_stock
value: 1
name: Block & Tackle Smokehouse and Tavern
parent_name: undefined
price: 19
product_id: 56
quantity: 1
sku: [empty string]
subtotal: 19.00
subtotal_tax: 0.00

2) [struct]
id: 15
image:
[struct]
id: [empty string]
src: [empty string]
meta_data:
[array]
1) [struct]
display_key: _reduced_stock
display_value: 1
id: 156
key: _reduced_stock
value: 1
name: Paddle 
parent_name: undefined
price: 54
product_id: 82
quantity: 1
sku: [empty string]
subtotal: 54.00
subtotal_tax: 0.00

First, I'm setting count to the Array Length.

<cfset count = #ArrayLen(webhook.line_items)# />

 That does return the length correctly. Then I am looping over the results;

<cfloop from="1" to="#count#" index="C">
<!--- database code here --->
#webhook.line_items["#c#"].product_ID#
</cfloop>

I'm getting the "You have attempted to dereference a scalar variable of type class java.lang.Double as a structure with members."

Suggestions on what I am doing wrong?

Thanks in advance for any help!

Gary

Views

196

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 ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

Try the following and see what happens:

(I am assuming the loop is surrounded by cfoutput tags)

 

<cfloop array="#webhook.line_items#" item="lineItem">
#lineItem#<br>
</cfloop>

 

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 ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

LATEST

Oh, and please let us know the result of trying that.

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