S
S
Sergey Ivchenko2016-04-21 11:46:07
Java
Sergey Ivchenko, 2016-04-21 11:46:07

Why is the MalformedJsonException thrown?

Hello Can you please tell me why I am getting the following error:


04-21 11:35:30.535 14997-15055/com.example.serg.yandextestproject E/AndroidRuntime: FATAL EXCEPTION: Thread-13020
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 890
at com.google.gson.Gson.fromJson(Gson.java:818)
at com.example.serg.yandextestproject.activities.PreviewActivity.run(PreviewActivity.java:102)
at java.lang.Thread.run (Thread.java:856)
Caused by: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 890
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
at com.google.gson.stream.JsonReader. skipQuotedValue(JsonReader.java:1100)
at com.google.gson.stream.JsonReader.skipValue(JsonReader.java:1229)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:170)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson .internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.example.serg.yandextestproject.activities.PreviewActivity.run(PreviewActivity.java:102) 
at java.lang.Thread.run(Thread.java :856) 

stackoverflow advice didn't help. I am using code:
Gson gson = new Gson();
                ArrayList<ArtistData> artists = gson.fromJson(new String(data, "UTF-8"), new TypeToken<List<ArtistData>>() {
                }.getType());

where data is a filled byte[]. Well, in fact, this is all done in a stream

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
guras256, 2016-04-28
@guras256

Weird question. Have you tried outputting your new String(data, "UTF-8") ?
Something tells me that you won't see any json there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question