• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to define JSONArray and JSONObject?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic