| Author |
Passing the JSON Array to the servlet
|
RaviNada Kiran
Ranch Hand
Joined: Jan 30, 2009
Posts: 528
|
|
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.
|
If you want something you never had do something which you had never done
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Convert jsonObj to String type using toString method and send it to the client with content-type as “text/xml” or “text/plain”.
HTH
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
RaviNada Kiran
Ranch Hand
Joined: Jan 30, 2009
Posts: 528
|
|
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
Joined: Jan 30, 2009
Posts: 528
|
|
|
I got it. Thanks .
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Jan 30, 2009
Posts: 528
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Jan 30, 2009
Posts: 528
|
|
"and use JSONObject#get(key) method"
This is what i was looking for .Thanks Again.
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Welcome
|
 |
 |
|
|
subject: Passing the JSON Array to the servlet
|
|
|