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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:15:51+00:00 2026-05-24T13:15:51+00:00

I am starting with the json: { Key1 : Value1, Key2 : Value2 }

  • 0

I am starting with the json:

{
    "Key1" : "Value1",
    "Key2" : "Value2"
}

I am then hard-coding this json in a string:

String json = "{ \"Key1\" : \"Value1\", \"Key2\" : \"Value2\" }";

Next I attempt to parse the json:

JSONObject content = null;
try {
    content = new JSONObject(json);
} catch (JSONException e) {
    e.printStackTrace();
    return null;
}       

String key1 = content.optString("Key1", null);

If I look at the hashmap created from the call to JSONObject, it looks correct:

{Key2=Value2, Key1=Value1}

But when I look at the value of the string key1 in the debugger, I get this:

[V, a, l, u, e, 1, U, U, U, U, U, U, U, U, U, U]

Where U appears to be unicode character 25A1 (White Square).

I’ve also tried the generic get(“Key1”) method, casting the result to a string and I get the same behavior?!?

  • 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-05-24T13:15:52+00:00Added an answer on May 24, 2026 at 1:15 pm

    I do not see an issue with your code, as this slight modification appears to work:

    public static void main(String[] args)
    {
        String json = "{ \"Key1\" : \"Value1\", \"Key2\" : \"Value2\" }";
    
        JSONObject content = null;
        try
        {
            content = new JSONObject(json);
        }
        catch (JSONException e)
        {
            e.printStackTrace();
            return;
        }
    
        String key1 = content.optString("Key1", null);
        System.out.print(key1 + "end!");
    }
    

    The console output says this: Value1end!

    When looking at the code in the debugger, I saw this:

    enter image description here

    If I were to venture a guess, it may just be additional buffer space the debugger is using to hold the String. Have you tried seeing what your code thinks it is?

    "Value1".equals(key1); //should return true if everything is working correctly.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting with this from Corey Goldberg: #!/usr/bin/env python import json import pprint import urllib2
Starting with 2005, VS started this behavior of when starting debugging session it spawns
Starting with the error: Error 81 The OutputPath property is not set for this
I'm just starting to dabble in consuming a JSON web service, and I am
I understand concepts of JSON ok, but after starting to use ebay's api, I
I have this url which is JSON webservice http://ws.geonames.org/weatherJSON?north=90&south=-9.9&east=-22.4&west=55.2 I need to write a
I have written a JSON parser that takes any valid json string and generates
I'm starting to use Dojo; this is (essentially) my introduction to AJAX. We have
Im just starting to get the hang of using json and Id like to
I'm just starting out with jQuery. I want to send JSON data to a

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.