我认为数据包含换行符(“\r\n”)这一事实可能有问题,因此我也尝试删除这些字符,以及删除空白(有很多,我想做一些讨厌的和不可打印的东西,但不在其中)。绳子在这里,很长。
var rawData: String = "{\r\n \"contacts\": [\r\n {\r\n \"id\": \"c200\",\r\n \"name\": \"Ravi Tamada\",\r\n \"email\": \"ravi@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c201\",\r\n \"name\": \"Johnny Depp\",\r\n \"email\": \"johnny_depp@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c202\",\r\n \"name\": \"Leonardo Dicaprio\",\r\n \"email\": \"leonardo_dicaprio@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c203\",\r\n \"name\": \"John Wayne\",\r\n \"email\": \"john_wayne@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c204\",\r\n \"name\": \"Angelina Jolie\",\r\n \"email\": \"angelina_jolie@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"female\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c205\",\r\n \"name\": \"Dido\",\r\n \"email\": \"dido@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"female\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c206\",\r\n \"name\": \"Adele\",\r\n \"email\": \"adele@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"female\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c207\",\r\n \"name\": \"Hugh Jackman\",\r\n \"email\": \"hugh_jackman@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c208\",\r\n \"name\": \"Will Smith\",\r\n \"email\": \"will_smith@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c209\",\r\n \"name\": \"Clint Eastwood\",\r\n \"email\": \"clint_eastwood@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c2010\",\r\n \"name\": \"Barack Obama\",\r\n \"email\": \"barack_obama@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c2011\",\r\n \"name\": \"Kate Winslet\",\r\n \"email\": \"kate_winslet@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"female\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n },\r\n {\r\n \"id\": \"c2012\",\r\n \"name\": \"Eminem\",\r\n \"email\": \"eminem@gmail.com\",\r\n \"address\": \"xx-xx-xxxx,x - street, x - country\",\r\n \"gender\" : \"male\",\r\n \"phone\": {\r\n \"mobile\": \"+91 0000000000\",\r\n \"home\": \"00 000000\",\r\n \"office\": \"00 000000\"\r\n }\r\n }\r\n ]\r\n}"
here
任何想法,想法,或工作样本将是伟大的。我知道这是一个听起来很常见的问题,但我几乎试过了所有的方法,还是没能奏效。