0

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.

Manjunath Rao
  • 1,397
  • 4
  • 26
  • 42

1 Answers1

1

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\"" +
            "}" +
            "]" +
            "}";
Community
  • 1
  • 1
searain
  • 3,143
  • 6
  • 28
  • 60
  • Good start! Perhaps mention _why_ they are having the problem, rather than just providing a solution? – cyberbit Jun 04 '16 at 22:07