• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing the JSON Array to the servlet

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Ranchers ,

Can you please help me how can i retrieve the JSONArray Object inside my servlet.


I am passing this arrayObj inside the send () using AJAX.

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convert jsonObj to String type using toString method and send it to the client with content-type as “text/xml” or “text/plain”.

HTH
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After getting the Object in the form of toString() inside the servlet . How can i retrieve each element on that Object ?

I read about eval() but confused.

How can i retrieve each project of the Object??
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thanks .
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I posted "Server to client" way, Here is "client to server" mode


• Create jsonObj JavaScript object
• Use “POST” HTTP method in the open method of the XMLHttpRequest object
• Pass jsonObj JavaScript object in the send method of XMLHttpRequest object


look for JSON.stringify();
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar , thanks .

But you did not answer my question . My question is after sending the JSONArray on to the send() with AJAX .
How can the servlet extract each property or element of the Object??
strangely , What you have posted is my question actually .
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're confusing each other

RaviNada Kiran wrote:
How can the servlet extract each property or element of the Object??

If you have a JSON string at server side, like "{key:value}" and you want to extract value/object then,

Create an JSONObject using JSONObject(String) constructor and use JSONObject#get(key) method.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"and use JSONObject#get(key) method"

This is what i was looking for .Thanks Again.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic