Problem with sending encoding polylines with json via ajax to the server
Im trying to send encoded polylines of google maps to the server with ajax to save them in the database. Im sending them through JSON and decode them at the server side. The problem is when the polyline gets too long the json_decode() function won't decode the json string anymore. Im making my ajax call with post and i've tried several things already like escaping the polylines etc. but nothing will work!
Working JSON example:
{"title":"a",
"type":"custom",
"POIS":["46","43"],
"polylines":[{
"points": "oot|H_bgd@rI{HjGkFz@_Ad@w@@eAxD~ClBpAxC`Ax@pAjAbCj@zA|@h@VqAr@wAdBeB|C}Bd@KfY}A",
"levels": "PEFEFGEFFEEFGEFEFEP"
}]
}
Not working JSON example:
{"title":"a",
"type":"custom",
"POIS":["46","43"],
"polylines":[{
"points": "uip|Hc|nd@v@GXoC`TwJV?VPvAhElAxF^bHtHd@zDd@Hj@]jf@KpC@v@F^VOx@HK`De@~EsAdHaEzPyDpMw\zaAqCvJo@tCmDjLyDtNkKvZmD`MmDfNuDnMuA~D_BpDiEhHcF|GxAzEfHhOORvChGjBrEJHnHxOzC~EtDzCpAnBdAzBpc@|hAjJvU`IxPbGdLn@|AJFb@rApAlHF|@fAjGF|AGvGDvCv@rGhA|Fr@fCjA`DfAbCHM`AOzAn@jBzEvBrEbCxCtAnAtAp@|InCf@Dz@Kn@BlDn@`@`@fApCfAqATOh@AxAvAHjA`@E`@L`@b@hGxI|EvF~CmMHInGfF|@bBdCjGvElKrBjGz@bD`@bBjAnGnAdLXjFJpCDtLSlIiBj`@g@tOCjLBdBLnDh@tE`@d@|A|FhA~Fl@pE~CtI`FbMX`@\LZ@`@WbEuFrD_HxBhBrDnBlGfCjFnAX\B`@Gb@sArEE|@g@zDe@`H@x@F\pAdFCv@QZn@lA",
开发者_运维技巧 "levels": "PFFEGEEFFEGEEEFFEFEGEEFFEEEFEEEFEFEGEEFEEEFFFEFEFEEEFEEEFEEFFEFEGEFFEFEFEFEEEFEFEEFFFEEFEFEFFEEGEEEFEEFEFEFEFEGEFEFEEGEEFEGEFEEGEEFEEFEEFEFP"
}]
}
You need to escape certain characters in your points property.
A quick look through your encoded polyline shows you have the character sequence "DpMw\zaA"
roughly a fifth of the way into the String.
Backslashes should be escaped with a backslash. So this should look like "DpMw\\zaA"
You should also escape double quotes in your JSON as the property points is constructed with a starting and ending double quote.
精彩评论