1

I'm getting the following error

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

There are some other solutions out there, but none have worked for me. Most seem to be talking about having to make Call<WordOfTheDay> into Call<List<WordOfTheDay>>, but since the json is not an array that does not help. I believe it's the JSON, but am not sure.

JSON

{"id":520687,"word":"imbricated","contentProvider":{"name":"wordnik","id":711},"note":"The word 'imbricated' comes from the Latin word imbricātus, covered with roof tiles, from imbrex, imbric-, roof tile, from imber, imbr-, rain.","publishDate":"2015-11-30T03:00:00.000+0000","examples":[{"url":"http://api.wordnik.com/v4/mid/ae14ef37c95d853a3ccc48d6590a9e1875a7e0920882657447b9dd4443c5d17553ca0c76787ecd04d0559596157a208c","text":"As it flows it takes the forms of sappy leaves or vines, making heaps of pulpy sprays a foot or more in depth, and resembling, as you look down on them, the laciniated lobed and imbricated thalluses of some lichens; or you are reminded of coral, of leopards 'paws or birds' feet, of brains or lungs or bowels, and excrements of all kinds.","title":"Walden, or Life in the woods","id":930392764},{"url":"http://amzn.to/1P1n9xM","text":"Pushing the door open, he noticed an inscription on the frame around the imbricated scales: Portae meae tantum regi.","title":"Paradiso, by José Lezama Lima","id":0},{"url":"http://amzn.to/1I938NP","text":"The Subaruns' epidermal scales shimmered like imbricated armour: biological photocells drinking scorching blue Pleiadean sunlight.","title":"Galactic North, Alastair Reynolds","id":0}],"definitions":[{"text":"Overlapping, like scales or roof-tiles; intertwined.","partOfSpeech":"adjective","source":"wiktionary"}]}

Retrofit 2.0

        Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(MainActivity.BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    //Initial Async Network Call Test
    WordAPI apiService = retrofit.create(WordAPI.class);
    Call<WordOfTheDay> call = apiService.getWordOfTheDay();
    call.enqueue(new Callback<WordOfTheDay>() {

        @Override
        public void onResponse(Response<WordOfTheDay> response, Retrofit retrofit) {
            int statusCode = response.code();
            WordOfTheDay temp = response.body();
            Log.d("temp","t");
        }

        @Override
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }
    });

Interface

public interface WordAPI {

@GET("/words.json/wordOfTheDay?api_key=??")
Call<WordOfTheDay> getWordOfTheDay();

}

2 Answers 2

1

May be you have invisible chars before first '{' ? Because error said that first element is string instead of object, it's may be if real json look like: @#${"id":...

Sign up to request clarification or add additional context in comments.

7 Comments

I'm using a 3rd party API so is there anything I can do on my end to "scrub" the invisible chars?
Try to debuging what is real json go to GSON parser, may be server returns text but not json, or you have problem in connection or so on.
How would I go about doing that?
Set breakpoint to method fromJson of GSON class and run as debug
So I am getting <!DOCTYPE HTML> as input. Is there any way I can on my end parse out the html?
|
0

Same issue with me. At last, got the root cause, pls keep sure the requested URI is correct.

3 Comments

What do you mean "pls keep sure the requested URI is correct.". Can you give us an example of what you did wrong?
For me, I made a mistake of requesting an incorrect URI, so got the unexpected string. I missed a "/" in URI.
You should clarify your answer, and explain that: As it will most likely help future readers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.