Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Web Services
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Web Services
Jsonp is not in expected format
joseph prabhu
Ranch Hand
Posts: 162
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The code i have written to get the data and to format in jsonp format. is below
private static ObjectMapper mapper = new ObjectMapper(); response.setContentType("application/json; charset=" + "UTF-8"); response.setCharacterEncoding("UTF-8"); Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); String q = request.getParameter("q"); String callback = request.getParameter("callback"); SearchAutoCompleteResponse resp = service.getAutoComplete(req); if (resp != null) suggestions = resp.getSuggestions(); if (callback != null) { json=new JSONPObject(callback, suggestions); System.out.println(json.getValue() +" " +json.getFunction() ); System.out.println(mapper); mapper.writeValue(writer, json); request.setAttribute("suggestions", json);
The expected output in
jsp
is
callback({"q":["A","B"]})
But my output is
callback(["A","B"]).
Please help how to format is
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Writing String Data to a File
wrestling with json
jQuery.getJSON callback not executing
Unicode CSV file.
File is Not Displaying
More...