Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9063645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:03:22+00:00 2026-06-16T16:03:22+00:00

i am creating json object to save data and then sending it to the

  • 0

i am creating json object to save data and then sending it to the servlet. But when i try to retrieve the object and display its contents in java servlet, it throws me an error saying ” A JSONObject text must begin with ‘{‘ at 1 [character 2 line 1]”. I do not know how to display the json object in java which is been sent from javascript. Here’s what i am doing:

Javascript Code:

var arrayOfObjects = [];
arrayOfObjects.push({"divid":imageinc,"xCordinates":Xcord,"yCordinates":Ycord,"Height":canvasWidth,"Width":canvasHeight, "PageNo":pageNum});

Displaying Javascript contents:

for (var i = 0; i < arrayOfObjects.length; i++) {
var object = arrayOfObjects[i];
for (var property in object) {
    alert(property + '=' + object[property]);
}
}

Sending object to servlet with jquery Ajax:

    var param = 'objarray=' +arrayOfObjects;

    $.ajax({
      url: '/ProjectName/finalXmlServGen',
      type: 'POST', 
      dataType: 'json',  
      data: param,
      success: function(result) {
          alert('SUCCESS');
      }
    });

I get success message once i call the ajax. Now, i am receiving this object in servlet as:

String objarray = request.getParameter("objarray").toString();
try {
        JSONObject jsonObj = new JSONObject(objarray);          

        String xmlString= XML.toString(jsonObj);
        System.out.println("JSON to XML: " + xmlString);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

The message i see in my console is the error ” A JSONObject text must begin with ‘{‘ at 1 [character 2 line 1]”. How do i parse the object and form an xml or string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:03:23+00:00Added an answer on June 16, 2026 at 4:03 pm

    On the Java side of things you need to convert the JSON array to a Java POJO bean first to be able to (easily) do something with it. There are multiple APIs to do this; Google GSON and Jackson are two possibilities.

    Jackson is used internally by Jersey, the reference implementation of the JAX-RS API; it works very well in my experience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating and sending a JSON Object with jQuery, but I cannot figure
I want to create a JSON object in java code and then pass it
I'm creating a JSON object like tags = {jon:[beef,pork],jane:[chicken,lamb]}; which was generated using php
In Ember.js, I'm creating a user object like so, populating it from a JSON
what I am doing is creating a form using JSON this form can then
I need to pass data from MYSQL database to android application by creating JSON
I am creating a series of object instances, the attributes of which i save
I am creating the following JSON object $(#btnSubmit).click(function () { var poll = {
I parsed data from json to corresponding class data and them want to save
I have this class that I persist by creating a JSON object based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.