Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to define JSONArray and JSONObject?

 
Thirupathi thota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic