A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Servlets
Author
how to define JSONArray and JSONObject?
Thirupathi thota
Greenhorn
Joined: Jun 15, 2011
Posts: 3
posted
Aug 30, 2011 04:52:42
0
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.HashMap
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import
java.io.IOException
;
@WebServlet(name="VideoServlet", urlPatterns={"/videos.do"})
public class VideosServlet extends
HttpServlet
{
protected void processRequest(
HttpServletRequest
request,
HttpServletResponse
response)
throws
ServletException
,
IOException
{
response.setContentType("text/javascript");
PrintWriter
out = response.getWriter();
String
customerId=(String)request.getParameter("customerId");
String domainName=(String)request.getParameter("domainName");
String format=(String)request.getParameter("format");
String callback=(String)request.getParameter("callback");
System.out.println("Input params==== :customerId= "+customerId+",domainName="+domainName+",format="+format+"callback="+callback);
java.util.ArrayList
videoList = WidgetData.getTweetVideos();
JSONArray jsonArray = JSONArray.fromObject(videoList);
HashMap
map = new
HashMap
();
map.put("videoList", jsonArray);
JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println("videos data==== : "+jsonObject);
out.println(callback + "(" +jsonObject+ ")");
}
}
I got error in this line
JSONArray jsonArray = JSONArray.fromObject(videoList);
I got another error in this line..
JSONObject jsonObject = JSONObject.fromObject(map);
Please tell me sir..
Thanking You sir
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
13
I like...
posted
Aug 30, 2011 08:10:54
0
Thirupathi thota wrote:
I got error in this line
...
I got another error in this line..
Keeping the nature of the errors a secret does not help anyone help you.
[
Smart Questions
] [
JSP FAQ
] [
Books by Bear
] [
Bear's FrontMan
] [
About Bear
]
I agree. Here's the link:
http://aspose.com/file-tools
subject: how to define JSONArray and JSONObject?
Similar Threads
how to, JSON data
Struts2 mapping query
Ext JS: how to populate grid with values from servlet
Reading Nested Json in Java
Spring 2.5 and JSON and JSP/AJAX working together
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter