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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:35:25+00:00 2026-06-01T17:35:25+00:00

I want to read a string which is formated like a JSON-File and print

  • 0

I want to read a string which is formated like a JSON-File and print it on screen.
Therefore I am useing the GSON-Library.

Everytime I want to compile I get an Exception in thread “main” com.google.gson.JsonSyntaxException Error

My Code looks like this

public class Test {

public static void main(String... args) throws Exception {
    String json = 
        "{"
                    + "'tag_name' : 'M mit Mbrunnen',"
                    + "'tag_id' : 'de_bw_xx_mstall',"
                    + "'tag_description': 'false',"
                    + "'tag_latitude': '42.704895',"
                    + "'tag_longitude': '10.652187',"
                    + "'tag_description_f_a': 'Ein weiteres Highlight in H',"
        + "}";

    // Now do the magic.
    Data data = new Gson().fromJson(json, Data.class);

    // Show it.
    System.out.println(data);
}
}

class Data {
private String tag_name;
private String tag_id;
private String tag_description;
private String tag_latitude;
private String tag_longitude;
private String tag_descrption_f_a;  

public String getName() { return tag_name; }
public String getId() { return tag_id; }
public String getDescription() { return tag_description; }
public String getLatitude() { return tag_latitude; }
public String getLongitude() { return tag_longitude; }
public String getDescriptionVoice() { return tag_descrption_f_a; }

public void setName(String name)                            { this.tag_name = name; }
public void setId(String id)                                { this.tag_id = id; }
public void setDescription(String description)              { this.tag_description = description; }
public void setLatitude(String latitude)                    { this.tag_latitude = latitude; }
public void setLongitude(String longitude)                  { this.tag_longitude = longitude; }
public void setDescriptionVoice(String descriptionVoice)    { this.tag_descrption_f_a = descriptionVoice; }

public String toString() {
    return String.format("%s,%s,%s,%s,%s,%s", tag_name, tag_id, tag_description, tag_latitude, tag_longitude, tag_descrption_f_a);
}
}

I am getting the error:

Exception in thread “main” com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 221
at com.google.gson.Gson.fromJson(Gson.java:769)
at com.google.gson.Gson.fromJson(Gson.java:721)
at com.google.gson.Gson.fromJson(Gson.java:670)
at com.google.gson.Gson.fromJson(Gson.java:642)
at Test.main(Test.java:19)
Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 221
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1298)
at com.google.gson.stream.JsonReader.nextInObject(JsonReader.java:739)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:382)
at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:349)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:169)
at com.google.gson.Gson.fromJson(Gson.java:755)
… 4 more

so the error happens here:

    // Now do the magic.
    Data data = new Gson().fromJson(json, Data.class);

I think my JSON-Data is provided in a wrong format.

  • 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-01T17:35:26+00:00Added an answer on June 1, 2026 at 5:35 pm

    i think your JSON in not well formed

    it should be something like this

    "{
        "tag_name": "M mit Mbrunnen",  // always use double quotes, single quote is not a valid json
        "tag_id": "de_bw_xx_mstall",
        "tag_description": "false",
        "tag_latitude": "42.704895",
        "tag_longitude": "10.652187",
        "tag_description_f_a": "Ein weiteres Highlight in H" // extra comma removed from here
    }"
    

    you can validate your JSON here http://jsonlint.com/

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

Sidebar

Related Questions

I'm want to read a simple string from a text file which is around
I'm using Apache POI 3.6, I want to read an excel file which has
I want to read a text file word by word in Qt4 (to which
I want to read a String character by character which is already in an
I want to read a String (Data) out of a text file and write
I have text file with string which code page is 1250. I want to
What I want to do is read a line from text file which contains
I would like to read an input file in C++, for which the structure
I have a string which has a version number. I want to read the
I have the following XML file with page nodes which I want to read

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.