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

  • Home
  • SEARCH
  • 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 8904319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:06:01+00:00 2026-06-15T02:06:01+00:00

My application has a Java servlet that reads a JSONObject out of the request

  • 0

My application has a Java servlet that reads a JSONObject out of the request and constructs some Java objects that are used elsewhere. I’m running into a problem because there are strings in the JSON that are encoded in ISO-8859-1. When I extract them into Java strings, the encoding appears to get interpreted as UTF-16. I need to be able to get the correctly encoded string back at some point to put into another JSON object.

I’ve tried mucking around with ByteBuffers and CharBuffers, but then I don’t get any characters at all. I can’t change the encoding, as I have to play nicely with other applications that use ISO-8859-1.

Any tips would be greatly appreciated.

It’s a legacy application using Struts 1.3.8. I’m using net.sf.json 2.2.4 for JSONObject and JSONArray.

A snippet of the parsing code is:

final JSONObject a = (JSONObject) i;
final JSONObject attr = a.getJSONObject("attribute");
final String category = attr.getString("category");

final String value = attr.getString("value");

I then create POJOs using that information, that are retrieved by another action class to create JSON to pass to the client for display, or to pass to other applications.

So to clarify, if the JSON contains the string “Juan Guzmán”, the Java String contains something like Juan Guzm?_An (I don’t have the exact one in front of me). I’m not sure how to get the correct diacritical back. I believe that if I can get a Java String that contains the correct representation, that Mezzie’s solution, below, will allow me to create the string with the correct encoding to put back into the JSON to serve back.

  • 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-15T02:06:02+00:00Added an answer on June 15, 2026 at 2:06 am

    I had the same issue and I am using the same technology as you are. In our case, it was UTF 8. so just change that to UTF-16

        public static String UTF8toISO( String str )
        {
            try
            {
                return new String( str.getBytes( "ISO-8859-1" ), "UTF-8" );
            }
            catch ( UnsupportedEncodingException e )
            {
                e.printStackTrace();
            }
            return str;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a Java application that has some dependencies (~10). I would like
I have a java singleton class that has my application settings. I used this
I have a regular JSP/Servlet/Java web application that is used for uploading pictures from
I have web application written in java using Eclipse. It has just one servlet
My Java application has multiple frames. Some of them are set to be always
I have a JSP java application that has a name AAA-master so currently my
I'm building a Java application that has parts that require daily update. I want
In a Java servlet based web application, is there any way to execute some
I'm developing a java servlet web application that manages information from multiple databases (all
I want to programmatically get the servlet containers port that my Java EE application

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.