• 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

How to confirm the JSON return correctly and handle it from given format.

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day,

Would like to get some guidance from guru here on how the JSON format look like and how could we used jQuery to retrieve the result.

The format show from FF10.2 from FireBug, is this the right format to return from respond server(using struts2-JSON plugin)?


if it is, how could we display record like above-mentioned?

The code that try from my end


doRenderJSONResult function:

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nakataa Kokuyo wrote:
The format show from FF10.2 from FireBug, is this the right format to return from respond server(using struts2-JSON plugin)?


Are the backslashes really in the response? They should not be. Backslashes are used in string literals to escape the quote characters but they are not part of JSON.

The actual response should be:
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

That's strange as FF 10 is showing me output that post, while Chrome showing whatever you show, so i guess the JSON format which was return are correct.

My question is how to get parse and display the output ?

 
Bear Bibeault
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
If properly formed JSON is returned, the parsed data will be passed as the first argument to the success callback.
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day Bear,

Here is really what I'm seeing from Chome console, I confuse on the correctness

Under response tab:


Under JSON tab:
 
Bear Bibeault
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
Well, are you getting the correct structure passed to the success callback?
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

I'm using struts2 and passing a big List to GSON plugin to generate out the a String, I modify little bit on the output and doesn't expose it here due to commercial data concern

Below is my action :



Output from response:
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bear,

here is my latest progress

from previous result of JSON, which i think is wrong due to it doesn't show pair "[]" in between of JSON data

Previous result:


Latest result with [] included :



by using following method:


Question:
1. It seem like the JSON data being parse to many tokens, as "data.JSONStr[0]" show me value of "[" , but i can't figure out how to get the whole first record from JSON.
 
Bear Bibeault
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
Please use proper indentation when posting code.

I would simply do a console.log() of data in the success callback and inspect the result to see of the correct construct is being returned. If not, then you know the returned JSON string is not correctly formed.
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the indentation, Bear. I hope it is better now.

Could you please help me to understand in what situation, data.JSONStr[0] become value of "[" , and what is syntax to get the first record of originNode value ?

Between, could you please show me sample of how the correct structure for list of custom object should be ?

Take for instance, there are student list which contain two records of {Name, address, age}.

 
Bear Bibeault
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
Again, if you're getting a data value of "[", which is a JSON delimiter, not a value, I don;t think that the JSON is properly formatted. It almost looks as if the JSON string is being passed though a method that is escaping the quotes. So I don;t think that the problem is on the client, but on the server.

Use the JavaScript console to look at the raw value being returned as the response. In Chrome, that would be under the Network section.
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bear,

you are right on the JSON structure which is incorrect form, it was due to my backend action which miss out some getter/setter method for the custom object before send back to client.
 
reply
    Bookmark Topic Watch Topic
  • New Topic