0

JSON配列を文字列にしようとしていますが、毎回このトークンを削除するなどのエラーが発生します。私がしている何か問題はありますか?

private String jString = "{
    \"geodata\": [
        {
                \"id\": \"1\",
                \"name\": \"Jenifer Hathway\",
                \"email\": \"jh@gmail.com\",
                \"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\": \"johnny_depp@gmail.com\",
                \"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\"
                }
        }

    ]
}";
4

2 に答える 2

3

Javaは複数行の文字列をサポートしていません。

private String jString = "{"
+ "    \"geodata\": ["
+ "        {"
+ "                \"id\": \"1\","
+ "                \"name\": \"Jenifer Hathway\","
+ "                \"email\": \"jh@gmail.com\","
+ "                \"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\": \"johnny_depp@gmail.com\","
+ "                \"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\""
+ "                }"
+ "        }"
+ "    ]"
+ "}";
于 2012-08-08T20:50:29.043 に答える
0

この行に別のタイプミスがあります

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

する必要があります

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

他の人が提案したように、私もすべての行をエスケープしようとします

于 2012-08-08T20:52:33.597 に答える