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 8910439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:41:24+00:00 2026-06-15T03:41:24+00:00

this is JSON string 1 {title:[1,2], amount:[1,2]} this is JSON string 2 {title:, amount:}

  • 0

this is JSON string 1

{"title":["1","2"], "amount":["1","2"]}

this is JSON string 2

{"title":"", "amount":""}

string 1 is created when I enter values in form and string 2 is created when I dont,
I want to know if the string is in format 1 that is title is an array [“1”, “2”] or format 2 that is title is just a string “” on the server side in a servlet, before I parse it. is there any way of doing so?

this is my previous question,
How do I parse this JSON string using GSON in servlet

which is solved but as you can see there i have class Data which has instance variables of type ArrayList, so when I parse it with this line

Data data = gson.fromJson(param, Data.class);

it throws exception

 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 24

because as I have declared ArrayList, it expects array only in json to parse it without any exceptions….but when I dont enter values in my form it doesnt create json string as

{"title":[], "amount":[]}

rather it creates like this

{"title":'', "amount":''}

which has string as value, which causes parsing to throw exception

  • 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-15T03:41:26+00:00Added an answer on June 15, 2026 at 3:41 am

    Check Google GSON it allows you to parse JSON server side.

    It goes something like this:

     String jsonString = request.getParameter("jsonParemeter");
     Gson gson = new Gson();
     Map fromJsonMap = gson.fromJson(jsonString, HashMap.class);
    
     Object object = fromJsonMap.get("title");
     if (object instanceof Collection) {
      // then is it's your array
     }
     else {
       // it's not
     } 
    

    If, for example, I run the following example code:

    String json1 = "{\"title\":[\"1\",\"2\"], \"amount\":[\"1\",\"2\"]}";
    String json2 = "{\"title\":\"\", \"amount\":\"\"}";
    
    Gson gson = new Gson();
    HashMap map = gson.fromJson(json1, HashMap.class);
    HashMap map2 = gson.fromJson(json2, HashMap.class);
    
    System.out.println(map);
    System.out.println(map2);
    
    System.out.println(map.get("amount").getClass());
    System.out.println(map2.get("amount").getClass());
    

    I get as output:

    {amount=[1, 2], title=[1, 2]}
    {amount=, title=}
    class java.util.ArrayList
    class java.lang.String
    

    If I understood you correctly I think it suits you 100%

    UPDATE

    Since you are trying to deserialize your JSON string directly to a Data object, if you want to keep doing that direct deserialization you have to use a custom deserialization mechanism

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

Sidebar

Related Questions

I have a JSON string array of objects like this. [{id:4,rank:adm,title:title 1}, {id:2,rank:mod,title:title 2},
Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
I have a JSON string that looks like this: { package1: { type: envelope,
I'm getting this json string info from the server : {members:[[sd2840d,Johny],[jkld341,Marry]]} So I store
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
I'm checking if an object in a JSON string exists using this: JSONObject json
I have a YQL output JSON string at this URL: YQL JSON I found
I would like to serialize this object to JSON String public class Person {
This is the structure of my JSON: string sample = [{'Disp_Name':'avi garg', 'emailId':'avi@india.com', 'fName':'avi',

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.