Manjunath Rao
Manjunath Rao

Reputation: 1511

"Illegal line end in string literal" using JSON data in Android Studio

I have read many posts but did not help me in solving this problem. Really hope this is not a duplicate question. I have been studying about JSON parsing in Android, and when I copied the below JSON data from tutorialspoint into Android Studio, it is giving me an error - "illegal line end in string literal"

String strJson="
        {            \"Employee\" :[
            {
                \"id\":\"01\",
                \"name\":\"Gopal Varma\",
                \"salary\":\"500000\"
            },
            {
                \"id\":\"02\",
                \"name\":\"Sairamkrishna\",
                \"salary\":\"500000\"
            },
            {
                \"id\":\"03\",
                \"name\":\"Sathish kallakuri\",
                \"salary\":\"600000\"
            }
            ]
        }";

Please help me to solve this problem, so I can master the JSON parsing technique.

Upvotes: 0

Views: 1106

Answers (1)

searain
searain

Reputation: 3301

See the post about Java multiple line string

Java multiline string

Use this instead,

String strJson = "{" +
            "\"Employee\" :[" +
            "{" +
            " \"id\":\"01\"," +
            "\"name\":\"Gopal Varma\"," +
            "\"salary\":\"500000\"" +
            "}," +
            "{" +
            "\"id\":\"02\"," +
            "\"name\":\"Sairamkrishna\"," +
            "\"salary\":\"500000\"" +
            "}," +
            "{" +
            "\"id\":\"03\"," +
            "\"name\":\"Sathish kallakuri\"," +
            "\"salary\":\"600000\"" +
            "}" +
            "]" +
            "}";

Upvotes: 1

Related Questions