--Karl
____________
Karl Swedberg
On Jun 29, 2009, at 1:25 PM, expresso wrote:
Mike thanks a lot. That is so weird. I got some ideas from
http://docs.jquery.com/GetJSON and as you can see from the example
it's using data.items.
it's working now. I just wonder why the jQuery example is using
data.items
On Jun 29, 12:19 pm, "Michael Geary" <m...@mg.to> wrote:That's right, your JSON is perfectly valid. You can test it at:www.jsonlint.orgHere's the formatted output from that site, with the image tags elided forclarity, and comments added showing how you'd access each part of itdirectly in JavaScript:// Data[// Data[0]{// Data[0].ImageTag"ImageTag": "..."},// Data[1]{// Data[1].ImageTag"ImageTag": "..."}]As you can see, what you have is an array of two elements. Each of thoseelements is an object with a single property named ImageTag with a stringvalue.Now back to your code. This is where it goes wrong:$.each(Data.items, function(i, item) {...});"Data" here is the JSON data, and you're trying to get its "items" propertyand use it as an array. But there is no "items" property - Data itself isthe array, so you'd use it directly:$.each(Data, function(i, item) {...});JSON that would work with your original code using Data.items would looklike this:// Data{// Data.items"items": [// Data.items[0]{// Data.items[0].ImageTag"ImageTag": "..."},// Data.items[1]{// Data.items[1].ImageTag"ImageTag": "..."}]}BTW, I suggest using variable names that begin with lower case. The uppercase first letter makes people think it's the name of a constructor.-MikeFrom: expressosome tells me that my original JSON is totally valid with the [ and ]On Jun 29, 11:03 am, MorningZ <morni...@gmail.com> wrote:http://en.wikipedia.org/wiki/JSONwill show you what it should look like... notice theoutside symbolsare { ... }, not [ .... ]again, you should look at this if you are working with .NETand JSON,it really takes all this guess work from the equation:http://james.newtonking.com/pages/json-net.aspxOn Jun 29, 12:01 pm, expresso <dschin...@gmail.com> wrote:Ok, so what should it be wrapped in or how should I reformat this?On Jun 29, 10:58 am, MorningZ <morni...@gmail.com> wrote:Wow, is posting the same thing every 3 mins to bump your topicannoying....Anyways,your results wrapped in [ .... ] signifies an Array, not a JSONobject.... hence ".getJSON" has no idea what to do with itOn Jun 29, 11:53 am, expresso <dschin...@gmail.com> wrote:So is this valid JSON that jQuery can parse? or do I need aninitial level such as "Images":[{"Images" :[{"ImageTag":"<imgsrc="http://www.xxx.com/image/473.jpg"alt="">"},{"ImageTag":"<imgsrc="http://www.xxx.com/image/4852.jpg"alt="">"} ]]On Jun 29, 10:37 am, expresso <dschin...@gmail.com> wrote:Ok, figured out that data.items is undefined. Not sure whybecause here's the json my url returns:[{"ImageTag":"<imgsrc="http://www.xxx.com/image/473.jpg"alt="">"},{"ImageTag":"<imgsrc="http://www.xxx.com/image/4852.jpg"alt="">"}]On Jun 29, 10:33 am, expresso <dschin...@gmail.com> wrote:I get the following error:G is undefinedinit()()jquery-1....2.min.js (line 12)(?)()()Carousel.aspx(line 30) I()jquery-1....2.min.js (line 19)F()()jquery-1....2.min.js (line 19) [Break on this error](function(){var l=this,g,y=l.jQuery,p=l.....each(function(){o.dequeue(this,E)})}});in jquery-1.3.2.min.jswhen I call this method of mine:$.getJSON("http://localhost:59396/xxx/xxxHandler.ashx?action=xxxjson",function(Data) {$.each(Data.items, function(i, item) {alert('got here');carousel.add(i,mycarousel_decodeEntities(item.ImageTag));if (i == 3) return false;});});I know I can get inside function(Data){ and thatthe errorstarts at $.each I believe
No comments:
Post a Comment