Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes how to define JSONArray and JSONObject? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to define JSONArray and JSONObject?" Watch "how to define JSONArray and JSONObject?" New topic

how to define JSONArray and JSONObject?

Thirupathi thota

Joined: Jun 15, 2011
Posts: 3
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;

@WebServlet(name="VideoServlet", urlPatterns={"/"})

public class VideosServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
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

Joined: Jan 10, 2002
Posts: 62272

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: how to define JSONArray and JSONObject?