Module, Plugin

Archived
Forum
(read-only)

Rest

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Phil Sturgeon

     

nested nameclash from a json api

Support Request

o4
o4

hi,

I am using rest to query a json file and it works great! so far…

there’s just one thing:

here’s the json file:

[{"timestamp":1371722400,"tide":[{"timestamp":1371694797,"shift":3,"state":"Marea Alta"},{"timestamp":1371716769,"shift":0.6,"state":"Marea Baja"},{"timestamp":1371739775,"shift":3,"state":"Marea Alta"},{"timestamp":1371761712,"shift":0.5,"state":"Marea Baja"}],"unit":"m","sunriseTwilight":1371707173,"sunrise":1371709345,"sunsetTwilight":1371767326,"sunset":1371765154,"images":{"full":"http:\/\/charts.metcentral.com\/tide\/9d87ea0c7e0de1ea702033acbe40403c.png"}}] 

there’s a nested timestamp field within tide, and a root timestamp.
here’s the ee template code I use:

{exp:rest url="http://magicseaweed.com/api/xxxxxxx/tide/?spot_id={segment_3}" offset="0" limit="1" record_type="m" verb="get" format="json" parse="inward"}
 
<li>timestamp{timestamp} {exp:nice_time date="{timestamp}" relative="no" format="%H:%i"}</li>
 <
li>
 
tide:
  <
ul
  
{tide}
   
<li>timestamp{timestamp}</li>
   <
li>time{exp:nice_time date="{timestamp}" relative="no" format="%H:%i"}</li>
   <
li>shift{shift}{unit}</li>
   <
li>state{state}</li>
   <
li>---</li>
  
{/tide}
  
</ul>
 </
li>
 <
li>unit {unit}</li>
 <
li>sunriseTwilight{sunriseTwilight} {exp:nice_time date="{sunriseTwilight}" relative="no" format="%H:%i"}</li>
 <
li>sunrise{sunrise} {exp:nice_time date="{sunrise}" relative="no" format="%H:%i"}</li>
 <
li>sunsetTwilight{sunsetTwilight} {exp:nice_time date="{sunsetTwilight}" relative="no" format="%H:%i"}</li>
 <
li>sunset{sunset} {exp:nice_time date="{sunset}" relative="no" format="%H:%i"}</li>
 <
li>
  
images
  {images}
  
<ul>
   <
li><img src="{full}" /></li>
  </
ul>
  
{/images}
 
</li>
{/exp:rest} 

the nested timestamp variable will always render as the root timestamp variable.
now it’s a bit hard to ask the guys to change the api to a better naming, so I kindly ask you on what to do so that it works?!

here’s the rendered template:
———————————————-
timestamp: 1371722400 12:00
tide:

  timestamp: 1371722400
  time: 12:00
  shift: 3m
  state: High
  —-
  timestamp: 1371722400
  time: 12:00
  shift: 0.6m
  state: Low
  —-
  timestamp: 1371722400
  time: 12:00
  shift: 3m
  state: High
  —-
  timestamp: 1371722400
  time: 12:00
  shift: 0.5m
  state: Low
  —-

unit m
sunriseTwilight: 1371707173 07:46
sunrise: 1371709345 08:22
sunsetTwilight: 1371767326 00:28
sunset: 1371765154 23:52
images ...
———————————————

the bold timestamp values should be all different, but they’re all the same as the root…

any help highly appreciated!!!
stefan

o4
# 1
o4

since it’s rather urgent that the problem is solved, and I don’t want to change the add-on or use php, I offer 50$ for the fix!

please help!
stefan

o4
# 2
o4

I had to find another solution.
really disappointed from the lack of support here.

:(

o4
# 3
o4

hi phil,

every now and then I try to use this add-on but it doesn’t work with nested loops.
this time I have the following situation:

{exp:rest url="http://de.pinterest.com/swatchwatches/swatch-prime-line.rss" base="item" debug="yes" format="xml"} {!-- debug="yes" --}
 
<li>{title}</li>
 <
li>{link}</li>
 <
li>{description}</li>
 <
ul>
  
{item}
   
<li>{title}</li>
   <
li>{link}</li>
   <
li>{guid}</li>
   <
li>{description}</li>
  
{/item}
 
</ul>
{/exp:rest} 

and of course the {title} variable inside the {item} loop will always take the value from the parent {title}

do you have ANY intention of fixing that?
could you perhaps point me to an add-on that doesn’t have this bug?

cheers
stefan

Adam Khan
# 4
Adam Khan

Stefan, there’s a parameter “base” to help with this issue. See Trevor Davis’s explanation, which helped me.