0

I am trying to make a JSON array into the String, but it is giving me error, like delete this token everytime. Is there anything wrong I am doing?

private String jString = "{
    \"geodata\": [
        {
                \"id\": \"1\",
                \"name\": \"Jenifer Hathway\",
                \"email\": \"[email protected]\",
                \"address\": \"xx-xx-xxxx,x - street, x - country\",
                \"gender\" : \"female\",
                \"latitude\" : \"37.33774833333334\",
                \"longitude\" : \"-121.88670166666667\",
                \"phone\": {
                    \"mobile\": \"+91 0000000000\",
                    \"home\": \"00 000000\",
                    \"office\": \"00 000000\"
                }
        },
        {
                \"id\": \"2\",
                \"name\": \"Johnny Depp\",
                \"email\": \"[email protected]\",
                \"address\": \"xx-xx-xxxx,x - street, x - country\",
                \"gender\" : \"male\",
                \"latitude\" : \"37.336453\",
                \"longitude\" : \"-121.884985\",
                \"phone\": {
                    \"mobile\": \"+91 0000000000\",
                    \"home\": \"00 000000\",
                    \"office\": \"00 000000\"
                }
        }

    ]
}";
5
  • I think you have a typo in this line: \"name\": Jenifer Hathway\", I think you want: \"name\": \"Jenifer Hathway\", Commented Aug 8, 2012 at 20:45
  • After making that changes, I have edited the question, still it is giving me delete token error. Something I am missing again.. Commented Aug 8, 2012 at 20:47
  • Can you show me some example? Commented Aug 8, 2012 at 20:48
  • I've take your string, removed the escape character and pasted into this [jsonformatter.curiousconcept.com/] JSON validator which returns back valid. Maybe try posting the error verbatim Commented Aug 8, 2012 at 20:50
  • I'm guessing you have this String inside a class. but if you don't, it will give you that error. Commented Aug 8, 2012 at 21:03

2 Answers 2

3

Java doesn't support multiline strings.

private String jString = "{"
+ "    \"geodata\": ["
+ "        {"
+ "                \"id\": \"1\","
+ "                \"name\": \"Jenifer Hathway\","
+ "                \"email\": \"[email protected]\","
+ "                \"address\": \"xx-xx-xxxx,x - street, x - country\","
+ "                \"gender\" : \"female\","
+ "                \"latitude\" : \"37.33774833333334\","
+ "                \"longitude\" : \"-121.88670166666667\","
+ "                \"phone\": {"
+ "                    \"mobile\": \"+91 0000000000\","
+ "                    \"home\": \"00 000000\","
+ "                    \"office\": \"00 000000\""
+ "                }"
+ "        },"
+ "        {"
+ "                \"id\": \"2\","
+ "                \"name\": \"Johnny Depp\","
+ "                \"email\": \"[email protected]\","
+ "                \"address\": \"xx-xx-xxxx,x - street, x - country\","
+ "                \"gender\" : \"male\","
+ "                \"latitude\" : \"37.336453\","
+ "                \"longitude\" : \"-121.884985\","
+ "                \"phone\": {"
+ "                    \"mobile\": \"+91 0000000000\","
+ "                    \"home\": \"00 000000\","
+ "                    \"office\": \"00 000000\""
+ "                }"
+ "        }"
+ "    ]"
+ "}";
Sign up to request clarification or add additional context in comments.

Comments

0

You have another typo on this line

\"home\": \"00 000000",

should be

\"home\": \"00 000000\",

I would also try escaping all the lines as suggested by others

Comments

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.