GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Servlets
Bookmark "how to define JSONArray and JSONObject?" Watch "how to define JSONArray and JSONObject?" New topic
Author

how to define JSONArray and JSONObject?

Thirupathi thota
Greenhorn

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

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]
 
GeeCON Prague 2014
 
subject: how to define JSONArray and JSONObject?