• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

processing json in jquery

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some json being returned from a servlet via a $.post().

I'm trying to get my callback to process the code and write a table to the dom based on that.


Here is what I'm thinking... any suggestions as to what I'm doing wrong would be great...



This should just create a single row for now. I'll worry about processing the jsonString (i'm thinking with a $.each()) after I get this going...
[ January 10, 2008: Message edited by: Bryce Martin ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why aren't you using $.getJSON()? Then you wouldn't need to worry about processing the JSON yourself.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Why aren't you using $.getJSON()? Then you wouldn't need to worry about processing the JSON yourself.



+1. I've pretty much left XML behind (which is funny considering the X in AJAX) and only return JSON formatted data or HTML. If returning JSON $.getJSON is awesome. You don't even have to eval as it does that for you.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting back the JSON string just fine. In the servlet I'm using StringTree JSON and returning it. Does something like the following look right? Is this how I would use this? Or am I missing something?



I'm having a hard time finding a good simple example of working with $.getJSON and then iterating through its values and working with them is some way.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget that last post. Since I've been playing with it I've been able to figure out the looping through the json objects. I'm going pretty strong now. When I get this thing working totally I'm going to post a tutorial because this is way more straight forward than anything I've seen posted anywhere yet. Anybody got a suggestion on where I should post it to get good visibility?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bryce Martin:
Anybody got a suggestion on where I should post it to get good visibility?



Do you have a weblog? Wherever you post it you are welcome to announce it in our Blatent Advertising forum. JQuery In Action also has very solid docco on using $.getJSON so be sure and check that out. The author should look familiar to you.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I've already expressed my longings for JQuery in Action. I just want to run it by the boss to make sure I get reimbursed for it

I don't have a technology weblog yet. Maybe I should start one. Heck, there are a lot of people that know a lot less than me and they have them. haha.

I've got this fully working with servlets and jsp (still working out a couple dom insertion techniques to make it quicker and more robust). I'm dynamically adding a table and then populating its rows off of the json response. Its pretty slick. Most of the stuff I've found laying around (even on jquery.com) pertains to PHP. And since JQuery in Action is still 4 days away from its full web release and more than 2 weeks from its print release you would need to spend $25 right now (and this is by fully trusting that Bear has great examples like usual) for a nice example. People haven't yet posted a whole lot in response to JQuery in Action in the way of examples and such, as far as I have seen. It takes time for people to pick it up, look at it, and apply and filter knowledge they've gained from it. So right now there isn't much out there for implementing this stuff in a very simple and straight forward manner for jsp/servlets.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bryce Martin:
Yes, I've already expressed my longings for JQuery in Action. I just want to run it by the boss to make sure I get reimbursed for it

I don't have a technology weblog yet. Maybe I should start one. Heck, there are a lot of people that know a lot less than me and they have them. haha.

I've got this fully working with servlets and jsp (still working out a couple dom insertion techniques to make it quicker and more robust). I'm dynamically adding a table and then populating its rows off of the json response. Its pretty slick. Most of the stuff I've found laying around (even on jquery.com) pertains to PHP. And since JQuery in Action is still 4 days away from its full web release and more than 2 weeks from its print release you would need to spend $25 right now (and this is by fully trusting that Bear has great examples like usual) for a nice example. People haven't yet posted a whole lot in response to JQuery in Action in the way of examples and such, as far as I have seen. It takes time for people to pick it up, look at it, and apply and filter knowledge they've gained from it. So right now there isn't much out there for implementing this stuff in a very simple and straight forward manner for jsp/servlets.



Right, I was by no means trying to discourage you from writing something up. In fact, at times we do accept articles from ranchers for our JavaRanch Journal. If you get something written up let us know and we'll consider it for inclusion.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gregg. That would be great I'm gonna go post a new problem in a new thread now. I'm so close I can taste it
 
reply
    Bookmark Topic Watch Topic
  • New Topic