Reputation: 19612
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\"
}
}
]
}";
Upvotes: 0
Views: 2674
Reputation: 637
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
Upvotes: 0
Reputation: 224903
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\""
+ " }"
+ " }"
+ " ]"
+ "}";
Upvotes: 3