0

This is my jsp file...

    <%@page import="java.util.*,java.util.List,java.util.ArrayList"%>
    <%@ page import="java.io.*,java.sql.*,java.text.*,pis.util.*"%>
    <%@ page  contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
    <%
        response.setContentType("application/json");
        String LedgerNo=request.getParameter("LedgerNo").trim();
        ResultSet rs = dm.getData("SELECT SaleNo , DisplayPrefix ,DisplayNo FROM sale 
           where CustomerName      like '"+ LedgerNo +"'");

        List<Map<String, Object>> menuList = new ArrayList<Map<String, Object>>();

       while (rs.next()) {
           System.out.println("SaleNo.."+rs.getInt(1));
           System.out.println("DisplayNo.."+rs.getString(2) +" "+ rs.getString(3));

           Map<String, Object> menuMap = new HashMap<String, Object>();
           menuMap.put("SaleNo",rs.getInt(1));
           menuMap.put("DisplayNo",rs.getString(3) );
           menuList.add(menuMap);

        } 

        System.out.println("menuList.."+menuList.toString());
        out.println(menuList);
        rs.close();
%>

I got my list as...

[{SaleNo=1, DisplayNo=K 1}, {SaleNo=2, DisplayNo=KC 1}]

I want to return this list as JSON . But it returns error,how can i achieve this?

1 Answer 1

1

You need to add quotes around Strings and use colon instead of equals. You don't need quotes around numbers.

your JSON should look like this...

[{"SaleNo":1, "DisplayNo":"K 1"}, {"SaleNo":2, "DisplayNo":"KC 1"}]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.