Mihael Mihael - 5 months ago 33
Android Question

Exception while trying to get data from json string

I am creating an android app that displays weather data it's getting in json format from an online API. For that I'm using the GSON libary.

I have the following JSON string, which i got from a map object:

String weather = jsonJavaRootObject.get("weather").toString();

It contains the following value:

{id=800, main=Clear, description=clear sky, icon=01n}

But when i try to create another Map object with that string i get an exception.

Map weatherMap = new Gson().fromJson(weather, Map.class);

The exception logcat report:

com.google.gson.stream.MalformedJsonException: Unterminated object at
line 1 column 43

I'm confused, because I have tried the same with another json string as the following and it worked just fine:

{temp=277.15, pressure=1021, humidity=80, temp_min=277.15, temp_max=277.15}


Strings have to be between double quotes

{id=800, main="Clear", description="clear sky", icon=01n}