Example JSON output....how would I access values?

6 views
Skip to first unread message

JonR

unread,
Aug 4, 2009, 4:27:10 PM8/4/09
to google-jstemplate
[{"foodid":"1","foodname":"Breakfast
food","fooditemid":"36","fooditemname":"Pork
Sandwich","description":"Ra Ra","price":"3.000"},
{"foodid":"1","foodname":"Breakfast
food","fooditemid":"37","fooditemname":"test","description":"blah","price":"1.000"},
{"foodid":"1","foodname":"Breakfast
food","fooditemid":"38","fooditemname":"ok","description":"Ysds","price":"2.000"},
{"foodid":"1","foodname":"Breakfast
food","fooditemid":"39","fooditemname":"Hello","description":"test","price":"4.000"},
{"foodid":"1","foodname":"Breakfast
food","fooditemid":"41","fooditemname":"test","description":"hi","price":"1.000"},
{"foodid":"2","foodname":"Lunch
food","fooditemid":"9","fooditemname":"Pickled Pork
Hearts","description":"Our specialty","price":"8.000"},
{"foodid":"2","foodname":"Lunch
food","fooditemid":"31","fooditemname":"Beef
Sandwich","description":"It's beeftastic!!","price":"4.500"},
{"foodid":"4","foodname":"testing","fooditemid":"35","fooditemname":"Tuna
Fish Sandwich","description":"Tuna Time","price":"45.000"},
{"foodid":"5","foodname":"Alien French Fry
food","fooditemid":"43","fooditemname":"ZorkFries","description":"Zorkalicious!","price":"34.000"},
{"foodid":"7","foodname":"Mooooo","fooditemid":"42","fooditemname":"Milk","description":"Real
Organic Milk","price":"3.000"}]

I have been using the Interactive Test template in conjunction with my
data. So far, I have been unable to get it to output my values. I was
hoping someone could give me an example of how I would access the
values from this JSON output. Each top level object has no name, and
there is no example in the documentation of how to select an object
that is unnamed. However, the JSON validates, so I'm guessing there is
a way to make this work.

Any help would be most appreciated.

mesch

unread,
Aug 4, 2009, 8:09:49 PM8/4/09
to google-jstemplate
> I have been using the Interactive Test template in conjunction with my
> data. So far, I have been unable to get it to output my values. I was
> hoping someone could give me an example of how I would access the
> values from this JSON output. Each top level object has no name, and
> there is no example in the documentation of how to select an object
> that is unnamed.

The data you supply at the top are in $this initially. So you would
jsselect="$this" to repeat for every element in the array, or use
$this in expressions as you like.

Christopher Hiller

unread,
Aug 4, 2009, 8:10:52 PM8/4/09
to google-j...@googlegroups.com
Would this work?

<div jsselect="$this">
<p jscontent="$this.foodid + ': ' + $this.foodname"></p>
</div>
--
christopher hiller
sr software engineer
decipher
34 nw 1st ave, ste 305
portland or 97209

(mesch 孟熙) Steffen Meschkat

unread,
Aug 4, 2009, 8:20:07 PM8/4/09
to google-j...@googlegroups.com
> Would this work?
>
> <div jsselect="$this">
>  <p jscontent="$this.foodid + ': ' + $this.foodname"></p>
> </div>

Yes it would. The recommended style would be to use elements for the
concatenation though:

<div jsselect="$this">
<p><span jscontent="$this.foodid"></span>: <span
jscontent="$this.foodname"></span></p>
</div>

This would make styling of the fields simpler (nay, possible). Also,
you can omit $this when accessing fields, though it may be good style
to use $this for clarity:

<div jsselect="$this">
<p><span jscontent="foodid"></span>: <span jscontent="foodname"></span></p>
</div>

Reply all
Reply to author
Forward
0 new messages